/* --- CSS VARIABLES (No Gradients) --- */
:root {
    /* Palette: Slate / Zinc inspired for High Contrast */
    --bg-body: #0f172a;
    /* Very Dark Blue/Slate */
    --bg-card: #1e293b;
    /* Lighter Slate */
    --bg-input: #334155;
    /* Input Background */
    --border-color: #475569;
    /* Visible Border */
    --border-hover: #64748b;
    /* Hover Border */

    /* Text Colors */
    --text-primary: #f8fafc;
    /* Almost White */
    --text-secondary: #cbd5e1;
    /* Light Gray */
    --text-muted: #94a3b8;
    /* Muted Gray */

    /* Accent Colors (Solid) */
    --accent-primary: #3b82f6;
    /* Solid Blue */
    --accent-hover: #2563eb;
    /* Darker Blue */
    --success: #10b981;
    /* Solid Green */
    --warning: #f59e0b;
    /* Solid Amber */
    --danger: #ef4444;
    /* Solid Red */

    /* Dimensions */
    --header-height: 70px;
    --sidebar-width: 260px;
    --bottom-nav-height: 65px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Typography */
    --font-main: 'Inter', sans-serif;
    --font-code: 'JetBrains Mono', monospace;

    /* Z-indices */
    --z-header: 100;
    --z-sidebar: 90;
    --z-modal: 200;
    --z-toast: 300;
    --z-cmd: 250;
}

/* --- RESET & BASE --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: grid;
    grid-template-areas:
        "header header"
        "sidebar main"
        "nav nav";
    grid-template-columns: 0 1fr;
    grid-template-rows: var(--header-height) 1fr var(--bottom-nav-height);
}

@media (min-width: 1024px) {
    body {
        grid-template-columns: var(--sidebar-width) 1fr;
        grid-template-rows: var(--header-height) 1fr 0;
    }
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-body);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* --- HEADER --- */
.app-header {
    grid-area: header;
    background-color: var(--bg-card);
    border-bottom: 3px solid var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: var(--z-header);
    position: relative;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background-color: var(--accent-primary);
    color: white;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
}

.brand-text h1 {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
}

.brand-text span {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.header-search {
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
    position: relative;
    display: none;
    /* Hidden on very small screens by default */
}

@media (min-width: 600px) {
    .header-search {
        display: block;
    }
}

.search-input {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px 10px 40px;
    border-radius: var(--radius-md);
    font-size: 14px;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
}

.cmd-hint {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--border-color);
    color: var(--text-secondary);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-code);
    pointer-events: none;
}

/* --- SIDEBAR --- */
.sidebar {
    grid-area: sidebar;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    display: none;
    flex-direction: column;
    padding: 24px 12px;
    z-index: var(--z-sidebar);
}

@media (min-width: 1024px) {
    .sidebar {
        display: flex;
    }
}

.side-nav-group {
    margin-bottom: 24px;
}

.side-nav-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 0 12px 12px;
    font-weight: 600;
}

.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.side-link:hover {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

.side-link.active {
    background-color: var(--accent-primary);
    color: white;
}

.side-link i {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

/* --- MAIN CONTENT AREA --- */
.main-content {
    grid-area: main;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 32px;
    scroll-behavior: smooth;
}

@media (max-width: 1023px) {
    .main-content {
        padding-bottom: calc(var(--bottom-nav-height) + 20px);
    }
}

/* --- COMMAND PALETTE --- */
.cmd-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: var(--z-cmd);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 100px;
}

.cmd-overlay.open {
    display: flex;
}

.cmd-palette {
    width: 100%;
    max-width: 600px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    animation: cmdSlideIn 0.2s ease-out;
}

@keyframes cmdSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.cmd-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.cmd-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 18px;
    outline: none;
}

.cmd-results {
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}

.cmd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
}

.cmd-item:hover,
.cmd-item.selected {
    background: var(--accent-primary);
    color: white;
}

.cmd-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cmd-item-name {
    font-weight: 500;
}

.cmd-item-category {
    font-size: 11px;
    opacity: 0.7;
    text-transform: uppercase;
}

.cmd-item-key {
    font-size: 12px;
    opacity: 0.5;
    font-family: var(--font-code);
}

/* --- SECTIONS & GRIDS --- */
.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

/* --- CARDS --- */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    height: 100%;
    animation: cardFadeIn 0.5s ease backwards;
}

.card:hover {
    transform: translateY(-8px);
    border-color: var(--accent-primary);
    box-shadow: 0 10px 20px -5px rgba(59, 130, 246, 0.3);
}

.card:active {
    transform: translateY(-4px);
}

@keyframes cardFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Staggered animation for grid items */
.card:nth-child(1) {
    animation-delay: 0.05s;
}

.card:nth-child(2) {
    animation-delay: 0.1s;
}

.card:nth-child(3) {
    animation-delay: 0.15s;
}

.card:nth-child(4) {
    animation-delay: 0.2s;
}

.card:nth-child(5) {
    animation-delay: 0.25s;
}

.card:nth-child(6) {
    animation-delay: 0.3s;
}

.card:nth-child(7) {
    animation-delay: 0.35s;
}

.card:nth-child(8) {
    animation-delay: 0.4s;
}

.card:nth-child(n+9) {
    animation-delay: 0.45s;
}

.card-icon {
    width: 48px;
    height: 48px;
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    color: var(--accent-primary);
    font-size: 20px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.card-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.card-fav-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: var(--border-color);
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s;
}

.card-fav-btn.active {
    color: var(--warning);
}

.card-fav-btn:hover {
    color: var(--text-primary);
}

/* --- DASHBOARD WIDGETS --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 32px;
}

@media (min-width: 768px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.widget {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.widget-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Specific Widget: Notes */
#notes-area {
    width: 100%;
    height: 120px;
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    color: var(--text-secondary);
    font-family: var(--font-code);
    font-size: 13px;
    resize: none;
}

#notes-area:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Specific Widget: Iframe Embed */
.iframe-container {
    width: 100%;
    height: 150px;
    background-color: #000;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    position: relative;
}

.iframe-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.iframe-label {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 8px;
    font-size: 10px;
    border-radius: 4px;
    pointer-events: none;
}

/* --- BOTTOM NAV --- */
.bottom-nav {
    grid-area: nav;
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
    position: relative;
    /* Ensure z-index works on mobile if needed */
}

@media (min-width: 1024px) {
    .bottom-nav {
        display: none;
    }
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s, background-color 0.2s;
    cursor: pointer;
    border: none;
    background: none;
    cursor: pointer;
    position: relative;
    user-select: none;
}

.nav-item i {
    font-size: 20px;
    margin-bottom: 2px;
}

.nav-item span {
    font-size: 10px;
    font-weight: 500;
}

.nav-item.active {
    color: var(--accent-primary);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 3px;
    background-color: var(--accent-primary);
    border-bottom-left-radius: 3px;
    border-bottom-right-radius: 3px;
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    /* Mobile bottom sheet style */
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

@media (min-width: 768px) {
    .modal-overlay {
        align-items: center;
    }
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    background-color: var(--bg-card);
    width: 100%;
    max-height: 90vh;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

@media (min-width: 768px) {
    .modal {
        width: 600px;
        max-height: 85vh;
        border-radius: var(--radius-lg);
        border: 1px solid var(--border-color);
        transform: scale(0.95);
        opacity: 0;
    }

    .modal-overlay.open .modal {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-overlay.open .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-card);
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    padding: 4px;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    background-color: var(--bg-body);
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background-color: var(--bg-card);
}

/* --- FORMS & BUTTONS IN MODAL --- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
    font-family: var(--font-code);
}

.btn {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.btn-secondary {
    background-color: var(--bg-input);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

/* --- CATEGORY TABS --- */
.category-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 20px;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.category-scroll::-webkit-scrollbar {
    display: none;
}

.cat-chip {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}

.cat-chip.active {
    background-color: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.cat-chip:hover:not(.active) {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

/* --- UTILS --- */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.empty-state {
    padding: 40px 0;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
}

.result-box {
    background-color: var(--bg-input);
    padding: 12px;
    border-radius: var(--radius-md);
    font-family: var(--font-code);
    font-size: 13px;
    color: var(--text-primary);
    word-break: break-all;
    min-height: 48px;
    margin-top: 8px;
    border: 1px solid var(--border-color);
    position: relative;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: var(--bg-card);
    border: 1px solid var(--accent-primary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 14px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 300;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* PWA Install Prompt */
.pwa-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--accent-primary);
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 500;
    transform: translateY(-100%);
    transition: transform 0.3s;
}

.pwa-banner.visible {
    transform: translateY(0);
}

.pwa-banner p {
    font-size: 14px;
    font-weight: 500;
}

.pwa-btn {
    background: white;
    color: var(--accent-primary);
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
}