/* =========================
   OVERLAY
========================= */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: 0.3s ease;
    z-index: 1050;
    /* below drawer (1100) */
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* =========================
   DRAWER
========================= */

.drawer {
    position: fixed;
    bottom: calc(-100% + 70px);
    left: 0;
    width: 100%;
    max-height: 90%;

    background: var(--card);
    color: var(--text);

    border-top-left-radius: 20px;
    border-top-right-radius: 20px;

    overflow-y: auto;
    overflow-x: hidden;

    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);

    transform: translateY(20px) scale(0.98);
    opacity: 0;

    transition:
        bottom 0.35s cubic-bezier(0.22, 1, 0.36, 1),
        transform 0.3s ease,
        opacity 0.25s ease;

    z-index: 1100;

    display: flex;
    flex-direction: column;

    display: flex;
    flex-direction: column;
    touch-action: pan-y; /* Allow vertical panning for drag */
}

/* Drag Handle for Bottom Sheets */
.drawer-handle {
    width: 36px;
    height: 4px;
    background: var(--muted);
    border-radius: 2px;
    margin: 8px auto 0;
    opacity: 0.5;
    flex-shrink: 0;
}

.drawer.active {
    bottom: calc(0px + env(safe-area-inset-bottom)); /* Sit at bottom */
    transform: translateY(0) scale(1);
    opacity: 1;
    min-height: 420px; /* Prevent dwarf mode */
}

/* Drawer Header */
.drawer-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 12px 20px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--card);
}

.drawer-header__actions {
    display: flex;
    justify-content: center;
}

.drawer-header__close {
    display: flex;
    justify-content: flex-end;
}

.drawer-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.close-btn {
    font-size: 26px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    padding: 4px;
    line-height: 1;
}

/* Drawer Content */
.drawer-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 400px; /* Ensure drawer expands for launcher */
}

/* Icon Colors — component-scoped tokens */
.icon-blue   { --icon-bg: #eff6ff;  --icon-fg: #1d4ed8; }
.icon-orange { --icon-bg: #fff7ed;  --icon-fg: #c2410c; }
.icon-pink   { --icon-bg: #fdf2f8;  --icon-fg: #be185d; }
.icon-green  { --icon-bg: #f0fdf4;  --icon-fg: #15803d; }
.icon-purple { --icon-bg: #faf5ff;  --icon-fg: #7e22ce; }
.icon-cyan   { --icon-bg: #ecfeff;  --icon-fg: #0e7490; }
.icon-teal   { --icon-bg: #f0fdfa;  --icon-fg: #0f766e; }
.icon-slate  { --icon-bg: #f8fafc;  --icon-fg: #334155; }

[class^="icon-"],
[class*=" icon-"] {
  background: var(--icon-bg);
  color: var(--icon-fg);
}

/* Dark Mode Icon Overrides */
html.dark .icon-blue   { --icon-bg: rgba(29, 78, 216, 0.15);   --icon-fg: #60a5fa; }
html.dark .icon-orange { --icon-bg: rgba(194, 65, 12, 0.15);   --icon-fg: #fb923c; }
html.dark .icon-pink   { --icon-bg: rgba(190, 24, 93, 0.15);   --icon-fg: #f472b6; }
html.dark .icon-green  { --icon-bg: rgba(21, 128, 61, 0.15);   --icon-fg: #4ade80; }
html.dark .icon-purple { --icon-bg: rgba(126, 34, 206, 0.15);  --icon-fg: #c084fc; }
html.dark .icon-cyan   { --icon-bg: rgba(14, 116, 144, 0.15);  --icon-fg: #22d3ee; }
html.dark .icon-teal   { --icon-bg: rgba(15, 118, 110, 0.15);  --icon-fg: #2dd4bf; }
html.dark .icon-slate  { --icon-bg: rgba(51, 65, 85, 0.15);    --icon-fg: #94a3b8; }

/* =========================
   APP GRID
========================= */

.app-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 20px;
}

/* App Tile */
.app {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;

    padding: 16px 8px;
    border-radius: 14px;

    background: var(--card);
    color: var(--text);

    box-shadow: 0 4px 10px var(--shadow);
    text-decoration: none;

    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.app:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 18px var(--shadow);
}

/* App Icon */
.app-icon {
    font-size: 28px;
    color: var(--primary);
    transition: transform 0.2s ease;
}

/* App Label */
.app-label {
    font-size: 13px;
    font-weight: 500;
}

/* =========================
   APP LAUNCHER GRID (Within Drawer)
   ========================= */

.app-launcher-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 24px 16px;
    width: 100%;
}

.launcher-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.launcher-item:active {
    transform: scale(0.9);
}

.launcher-icon {
    width: 60px;
    height: 60px;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--shadow), inset 0 0 0 1px rgba(255,255,255,0.1);
}

.launcher-icon .material-symbols-outlined {
    font-size: 30px;
}

.launcher-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    color: var(--muted);
    text-align: center;
}

/* =========================
   TRANSITIONS
   ========================= */

.navbar,
.drawer,
.drawer-header {
    transition: background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}