/* Root variables for theming */
:root[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-sidebar: #1e293b;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #64748b;
    --border-color: #e2e8f0;
    --card-bg: #ffffff;
    --card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --hover-bg: #f1f5f9;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
}

:root[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-sidebar: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --border-color: #334155;
    --card-bg: #1e293b;
    --card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3);
    --hover-bg: #334155;
    --accent-primary: #3b82f6;
    --accent-hover: #60a5fa;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.bg-primary { background-color: var(--bg-primary); }
.bg-secondary { background-color: var(--bg-secondary); }
.bg-tertiary { background-color: var(--bg-tertiary); }
.bg-sidebar { background-color: var(--bg-sidebar); }
.bg-card { background-color: var(--card-bg); }
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.border-color { border-color: var(--border-color); }

.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}


.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, var(--accent-primary), var(--accent-hover));
}

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

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

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

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

/* Animation utilities */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.4s ease-out;
}

/* Table styling */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:hover {
    background-color: var(--hover-bg);
}

/* Form inputs */
input, select, textarea {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    width: 100%;
    transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.flex {
    display: flex;
}

.modal-content {
    background-color: var(--card-bg);
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.3), 0 8px 10px -6px rgb(0 0 0 / 0.3);
    max-width: 42rem;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Tab Component */
.tab-btn {
    transition: all 0.2s ease;
    background: none;
    border-bottom-width: 2px;
    cursor: pointer;
}

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

.tab-btn.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

/* Static card - no hover lift (for detail pages with interactive content) */
.card-static {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
}

/* Print Styles */
@media print {
    aside, header, .no-print, .sidebar { display: none !important; }
    main { margin: 0 !important; padding: 0 !important; }
    .card, .card-static { box-shadow: none; border: 1px solid #e2e8f0; break-inside: avoid; }
    body { background: white !important; color: black !important; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Rich text editor */
.editor-btn.active {
    background-color: var(--bg-tertiary);
    color: var(--accent-primary);
}

[contenteditable]:empty::before {
    content: attr(data-placeholder);
    color: var(--text-tertiary);
    pointer-events: none;
}

[contenteditable]:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--accent-primary);
    border-radius: 0 0 0.5rem 0.5rem;
}

/* Full-page calendar */
.calendar-view-btn.active {
    background-color: var(--accent-primary);
    color: white;
}

.cal-day-cell {
    min-height: 100px;
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 0.25rem;
}

.cal-day-cell.today {
    background-color: rgba(59, 130, 246, 0.05);
}

.cal-day-cell.other-month {
    opacity: 0.4;
}

.cal-event {
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    margin-bottom: 0.125rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-time-slot {
    height: 48px;
    border-bottom: 1px solid var(--border-color);
}

/* ── SECTION COLOURS ──────────────────────────────────────────────────────── */
/* Applied to <html data-section="..."> so every element can use --section-accent */
html[data-section="dashboard"]    { --section-accent: #6B7280; --section-accent-light: rgba(107,114,128,0.1); }
html[data-section="sales"]        { --section-accent: #3B82F6; --section-accent-light: rgba(59,130,246,0.1); }
html[data-section="reservations"] { --section-accent: #10B981; --section-accent-light: rgba(16,185,129,0.1); }
html[data-section="products"]     { --section-accent: #F59E0B; --section-accent-light: rgba(245,158,11,0.1); }
html[data-section="operations"]   { --section-accent: #8B5CF6; --section-accent-light: rgba(139,92,246,0.1); }
html[data-section="finance"]      { --section-accent: #14B8A6; --section-accent-light: rgba(20,184,166,0.1); }
html[data-section="analytics"]    { --section-accent: #F43F5E; --section-accent-light: rgba(244,63,94,0.1); }
html[data-section="admin"]        { --section-accent: #6B7280; --section-accent-light: rgba(107,114,128,0.1); }

/* Fallback so --section-accent is always defined even if data-section is missing */
html { --section-accent: #6B7280; --section-accent-light: rgba(107,114,128,0.1); }

/* ── TOP MENU ─────────────────────────────────────────────────────────────── */
.top-menu {
    height: 48px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 0;
    z-index: 40;
    flex-shrink: 0;
}

.top-menu-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-right: 20px;
    border-right: 1px solid var(--border-color);
    margin-right: 8px;
    text-decoration: none;
    flex-shrink: 0;
}
.top-menu-logo svg   { width: 24px; height: 24px; color: var(--accent-primary); }
.top-menu-logo span  { font-weight: 600; font-size: 14px; color: var(--text-primary); }

.top-menu-sections {
    display: flex;
    align-items: center;
    gap: 0;
    flex: 1;
    overflow-x: auto;
    /* Hide scrollbar while keeping scroll behaviour */
    scrollbar-width: none;
}
.top-menu-sections::-webkit-scrollbar { display: none; }

.top-menu-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    height: 48px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 3px solid transparent;
    transition: all 0.15s ease;
    white-space: nowrap;
    flex-shrink: 0;
}
.top-menu-item:hover {
    color: var(--text-primary);
    background: var(--hover-bg);
}
.top-menu-item.active {
    color: var(--section-accent);
    border-bottom-color: var(--section-accent);
}
.top-menu-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.top-menu-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    padding-left: 12px;
    border-left: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* ── CONTEXTUAL SIDEBAR ───────────────────────────────────────────────────── */
.ctx-sidebar {
    width: 256px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.ctx-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.ctx-sidebar-section-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--section-accent);
    display: flex;
    align-items: center;
    gap: 8px;
}
.ctx-sidebar-section-label svg { width: 20px; height: 20px; }

.ctx-sidebar-quick-actions {
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

.ctx-quick-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--section-accent-light);
    color: var(--section-accent);
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.ctx-quick-btn:hover {
    border-color: var(--section-accent);
    background: var(--section-accent);
    color: white;
}
.ctx-quick-btn svg { width: 14px; height: 14px; }

.ctx-sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

.ctx-sidebar-group-label {
    padding: 12px 16px 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
}

/* Workflow step items */
.ctx-workflow-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    text-decoration: none;
    color: var(--text-secondary);
    transition: all 0.15s;
    position: relative;
}
.ctx-workflow-item:hover {
    color: var(--text-primary);
    background: var(--hover-bg);
}
.ctx-workflow-item.active {
    color: var(--section-accent);
    background: var(--section-accent-light);
    border-right: 3px solid var(--section-accent);
}

.workflow-badge {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    color: var(--text-secondary);
}
.ctx-workflow-item.active .workflow-badge {
    border-color: var(--section-accent);
    background: var(--section-accent);
    color: white;
}

.workflow-connector {
    position: absolute;
    left: 27px;
    top: 100%;
    width: 2px;
    height: 8px;
    background: var(--border-color);
    z-index: 1;
}

/* Standard sidebar items */
.ctx-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all 0.15s;
}
.ctx-nav-item:hover {
    color: var(--text-primary);
    background: var(--hover-bg);
}
.ctx-nav-item.active {
    color: var(--section-accent);
    background: var(--section-accent-light);
    border-right: 3px solid var(--section-accent);
}
.ctx-nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Recent items footer */
.ctx-recent {
    border-top: 1px solid var(--border-color);
    padding: 8px 0;
}
.ctx-recent-label {
    padding: 8px 16px 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
}
.ctx-recent-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 16px;
    font-size: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s;
}
.ctx-recent-item:hover { color: var(--text-primary); }
.ctx-recent-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── BREADCRUMBS ──────────────────────────────────────────────────────────── */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    font-size: 12px;
}
.breadcrumb-item {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s;
}
.breadcrumb-item:hover { color: var(--section-accent); }
.breadcrumb-separator { color: var(--text-tertiary); font-size: 10px; }
.breadcrumb-current   { color: var(--text-primary); font-weight: 500; }
.breadcrumb-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--section-accent);
    display: inline-block;
    margin-right: 2px;
    flex-shrink: 0;
}

/* ── MOBILE NAV ───────────────────────────────────────────────────────────── */
.mobile-nav-toggle { display: none; }

@media (max-width: 1023px) {
    .top-menu-sections { display: none; }

    .mobile-nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: none;
        background: none;
        color: var(--text-secondary);
        cursor: pointer;
        border-radius: 6px;
        margin-right: 4px;
    }
    .mobile-nav-toggle:hover { background: var(--hover-bg); }

    .ctx-sidebar {
        position: fixed;
        top: 48px;
        left: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    .ctx-sidebar.mobile-open { transform: translateX(0); }

    .mobile-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        top: 48px;
        background: rgba(0,0,0,0.5);
        z-index: 49;
    }
    .mobile-backdrop.show { display: block; }

    .mobile-section-strip {
        display: flex;
        gap: 4px;
        padding: 12px;
        border-bottom: 1px solid var(--border-color);
        overflow-x: auto;
        scrollbar-width: none;
    }
    .mobile-section-strip::-webkit-scrollbar { display: none; }

    .mobile-section-btn {
        width: 36px;
        height: 36px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--border-color);
        background: none;
        cursor: pointer;
        flex-shrink: 0;
        color: var(--text-secondary);
        text-decoration: none;
    }
    .mobile-section-btn.active {
        border-color: var(--section-accent);
        background: var(--section-accent-light);
        color: var(--section-accent);
    }
    .mobile-section-btn svg { width: 18px; height: 18px; }
}

@media (min-width: 1024px) {
    .mobile-section-strip { display: none !important; }
}

/* Print: strip all navigation chrome */
@media print {
    .top-menu, .ctx-sidebar, .breadcrumbs, .mobile-nav-toggle, .mobile-backdrop {
        display: none !important;
    }
}

/* Document builder */
.builder-block.dragging {
    opacity: 0.5;
    border: 2px dashed var(--accent-primary);
}

.builder-block.drag-over {
    border-top: 3px solid var(--accent-primary);
}

.drag-handle:active {
    cursor: grabbing;
}

/* Account tree */
.tree-toggle svg { transition: transform 0.2s ease; }
.tree-toggle.expanded svg { transform: rotate(90deg); }

/* Bank reconciliation */
.recon-item.selected {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
    background-color: rgba(59, 130, 246, 0.05);
}
.recon-item.matched { opacity: 0.4; pointer-events: none; }

/* Sidebar collapsible sections */
.sidebar-section-toggle .section-chevron {
    transition: transform 0.2s ease;
}
.sidebar-section-toggle.collapsed .section-chevron {
    transform: rotate(-90deg);
}

/* ─── Inventory Calendar ─────────────────────────────────────────────────── */
.inv-calendar-table {
    border-collapse: separate;
    border-spacing: 2px;
    width: auto;
}

.inv-calendar-table th,
.inv-calendar-table td {
    padding: 0;
    border-bottom: none;
}

.inv-room-col {
    min-width: 140px;
    padding-right: 1rem !important;
    vertical-align: middle;
}

.inv-cell {
    min-width: 42px;
    min-height: 48px;
    width: 42px;
    height: 48px;
    border-radius: 0.375rem;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: default;
    transition: filter 0.15s ease, border-color 0.15s ease;
    user-select: none;
}

.inv-cell:hover {
    filter: brightness(1.1);
    border-color: var(--accent-primary);
}

.inv-cell.available {
    background: rgba(52, 211, 153, 0.08);
    border-color: rgba(52, 211, 153, 0.25);
}

.inv-cell.low-stock {
    background: rgba(251, 191, 36, 0.08);
    border-color: rgba(251, 191, 36, 0.3);
}

.inv-cell.sold-out {
    background: rgba(248, 113, 113, 0.08);
    border-color: rgba(248, 113, 113, 0.3);
}

.inv-cell.stop-sale {
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 4px,
        rgba(248, 113, 113, 0.08) 4px,
        rgba(248, 113, 113, 0.08) 8px
    );
    border-color: rgba(248, 113, 113, 0.4);
}

.inv-cell.on-request {
    background: rgba(108, 143, 255, 0.08);
    border-color: rgba(108, 143, 255, 0.25);
}

.inv-cell.released {
    background: rgba(148, 163, 184, 0.08);
    border-color: rgba(148, 163, 184, 0.2);
    opacity: 0.6;
}

/* Legend swatch for stop-sale (used in toolbar legend) */
.inv-cell-legend-stop {
    width: 1rem;
    height: 1rem;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 3px,
        rgba(248, 113, 113, 0.35) 3px,
        rgba(248, 113, 113, 0.35) 6px
    );
    border: 1px solid rgba(248, 113, 113, 0.5);
}

/* Refund calculator tier highlight (active tier) */
.tier-row {
    transition: background-color 0.2s ease, border-color 0.2s ease;
}
