/* EnergyIQ — base stylesheet */

*, *::before, *::after { box-sizing: border-box; }

:root {
    --color-bg:       #f0f2f5;
    --color-surface:  #ffffff;
    --color-primary:  #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-text:     #111827;
    --color-muted:    #6b7280;
    --color-border:   #e5e7eb;
    --color-error:    #dc2626;
    --color-success:  #16a34a;
    --color-warning:  #d97706;
    --color-info:     #2563eb;
    --radius:         6px;

    /* Energy series — one color per entity, used in stat cards, tables and charts */
    --color-solar:        #16a34a;
    --color-consumption:  #2563eb;
    --color-grid-import:  #d97706;
    --color-grid-export:  #7c3aed;
    --color-soc:          #0d9488;
}

/* Series/status text utilities — replace inline style="color:#…" */
.text-solar       { color: var(--color-solar); }
.text-consumption { color: var(--color-consumption); }
.text-grid-import { color: var(--color-grid-import); }
.text-grid-export { color: var(--color-grid-export); }
.text-soc         { color: var(--color-soc); }
.text-success     { color: var(--color-success); }
.text-warning     { color: var(--color-warning); }
.text-error       { color: var(--color-error); }

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

/* ---------------------------------------------------------------------------
   Navbar
--------------------------------------------------------------------------- */
.navbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.1rem;
}

.navbar-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.navbar-links a {
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.9rem;
}

.navbar-links a:hover { color: var(--color-primary); }

.navbar-user {
    color: var(--color-muted);
    font-size: 0.875rem;
}

.btn-logout {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.3rem 0.75rem;
    font-size: 0.875rem;
}

/* ---------------------------------------------------------------------------
   Main content
--------------------------------------------------------------------------- */
.main-content {
    padding: 2rem 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* ---------------------------------------------------------------------------
   Alerts / flash messages
--------------------------------------------------------------------------- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error   { background: #fef2f2; color: var(--color-error);   border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--color-success); border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: var(--color-warning); border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: var(--color-info);    border: 1px solid #bfdbfe; }

/* ---------------------------------------------------------------------------
   Login page
--------------------------------------------------------------------------- */
.login-wrapper {
    min-height: calc(100vh - 56px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.login-title {
    text-align: center;
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
}

.login-subtitle {
    text-align: center;
    color: var(--color-muted);
    margin: 0 0 1.75rem;
    font-size: 0.9rem;
}

/* ---------------------------------------------------------------------------
   Forms
--------------------------------------------------------------------------- */
.form-group {
    margin-bottom: 1.1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
}

.form-input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: border-color .15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.form-error {
    display: block;
    color: var(--color-error);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

/* ---------------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------------- */
.btn {
    display: inline-block;
    padding: 0.55rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background .15s;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

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

.btn-full { width: 100%; text-align: center; margin-top: 0.5rem; }

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); }

.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.85rem; }

/* ---------------------------------------------------------------------------
   Cards
--------------------------------------------------------------------------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.form-card { margin-bottom: 1.25rem; }

/* ---------------------------------------------------------------------------
   Page header (title + action button row)
--------------------------------------------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-header h1 { margin: 0; font-size: 1.5rem; }

/* ---------------------------------------------------------------------------
   Section titles inside cards
--------------------------------------------------------------------------- */
.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}
.section-hint {
    color: var(--color-muted);
    font-size: 0.875rem;
    margin: -0.5rem 0 1rem;
}

/* ---------------------------------------------------------------------------
   Stat cards
--------------------------------------------------------------------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card { text-align: center; padding: 1.25rem 1rem; }
.stat-card--warning { border-color: var(--color-warning); background: #fffbeb; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--color-muted); margin-top: 0.35rem; }
.stat-delta { font-size: 0.72rem; color: var(--color-muted); margin-top: 0.3rem; }

/* ---------------------------------------------------------------------------
   Tables
--------------------------------------------------------------------------- */
/* Table card header: title left, actions (CSV download) right */
.table-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.75rem;
}

/* Collapsible table container */
.table-details summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--color-muted);
    padding: 0.25rem 0;
    user-select: none;
}
.table-details summary:hover { color: var(--color-text); }
.table-details[open] summary { margin-bottom: 0.5rem; }

/* Scroll containment: wrap wide tables so the page never scrolls sideways */
.table-scroll {
    overflow-x: auto;
    max-height: 480px;
    overflow-y: auto;
}
.table-scroll .table th {
    position: sticky;
    top: 0;
    background: var(--color-surface);
    z-index: 1;
    box-shadow: 0 1px 0 var(--color-border);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.table th {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-muted);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}
.table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--color-bg); }
.table a { color: var(--color-primary); text-decoration: none; }
.table a:hover { text-decoration: underline; }
.table code { font-size: 0.85rem; background: var(--color-bg); padding: 0.1rem 0.35rem; border-radius: 3px; }

/* ---------------------------------------------------------------------------
   Badges
--------------------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-muted   { background: #f3f4f6; color: #6b7280; }
.badge-error   { background: #fee2e2; color: #b91c1c; }

/* ---------------------------------------------------------------------------
   Form grid (2-column layout for admin forms)
--------------------------------------------------------------------------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0 1.5rem;
}
.form-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--color-muted);
    margin-top: 0.25rem;
}

/* ---------------------------------------------------------------------------
   Detail view (site profile display)
--------------------------------------------------------------------------- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
}
.detail-heading {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-muted);
    margin: 0 0 0.5rem;
}
.detail-list { margin: 0; }
.detail-list dt {
    font-size: 0.8rem;
    color: var(--color-muted);
    margin-top: 0.5rem;
}
.detail-list dd {
    margin: 0;
    font-size: 0.95rem;
}

/* ---------------------------------------------------------------------------
   Log panel
--------------------------------------------------------------------------- */
.log-panel {
    background: #1e1e2e;
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
}
.log-line {
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
}
.log-line--error    { color: #f87171; }
.log-line--critical { color: #fb923c; font-weight: 600; }

/* ---------------------------------------------------------------------------
   Range selector (client dashboard)
--------------------------------------------------------------------------- */
.range-selector {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.65rem 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.range-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.range-group-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-muted);
    margin-right: 0.2rem;
}

.range-divider {
    width: 1px;
    height: 22px;
    background: var(--color-border);
    flex-shrink: 0;
}

.range-custom {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.range-date {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    width: 130px;
    transition: border-color .15s;
}

.range-date:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.range-to-label {
    font-size: 0.85rem;
    color: var(--color-muted);
}

.range-btn {
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.82rem;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.range-btn:hover { background: var(--color-bg); }

.range-btn--active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
    font-weight: 600;
}

/* Navigation-in-progress feedback: busy cursor + sweeping top bar */
body.range-loading { cursor: progress; }
body.range-loading::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 100%;
    background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
    animation: range-loading-sweep 1s linear infinite;
    z-index: 9999;
    pointer-events: none;
}
@keyframes range-loading-sweep {
    from { transform: translateX(-100%); }
    to   { transform: translateX(100%); }
}

/* ---------------------------------------------------------------------------
   Chart layout
--------------------------------------------------------------------------- */
.chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .chart-row { grid-template-columns: 1fr; }
}

.chart-wrap {
    position: relative;
    height: 280px;
}
/* Required for chartjs-plugin-zoom touch/pinch events on mobile */
.chart-wrap canvas {
    touch-action: none;
}

.chart-hint {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.72rem;
    color: var(--color-muted);
    min-height: 1.6rem;
}

/* ---------------------------------------------------------------------------
   Empty / no-data state
--------------------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--color-muted);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.empty-state h2,
.empty-state h3 {
    color: var(--color-text);
    margin: 0 0 0.5rem;
}

.empty-state p {
    max-width: 480px;
    margin: 0.4rem auto;
    font-size: 0.95rem;
}

/* ---------------------------------------------------------------------------
   Misc
--------------------------------------------------------------------------- */
.text-muted { color: var(--color-muted); }
.text-muted a { color: var(--color-primary); }

/* ---------------------------------------------------------------------------
   Sidebar layout (authenticated pages)
--------------------------------------------------------------------------- */
body.sidebar-layout {
    display: flex;
    min-height: 100vh;
    background: var(--color-bg);
    overflow-x: hidden;
}

.sidebar {
    width: 220px;
    background: #1e293b;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 100;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Collapsed: narrow strip */
body.sidebar-collapsed .sidebar {
    width: 56px;
}

/* Hover on collapsed: expand as overlay (content doesn't move) */
body.sidebar-collapsed .sidebar:hover {
    width: 220px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05rem;
    padding: 1.25rem 1rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    letter-spacing: -0.01em;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-logo-icon { flex-shrink: 0; }

.sidebar-logo-text {
    white-space: nowrap;
    transition: opacity 0.15s;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
}

.nav-section-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    padding: 0.9rem 1rem 0.3rem;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #94a3b8;
    text-decoration: none;
    padding: 0.45rem 1rem;
    font-size: 0.875rem;
    border-radius: 4px;
    margin: 0 0.5rem;
    transition: background 0.12s, color 0.12s;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }

.nav-item--active {
    background: var(--color-primary);
    color: #fff !important;
    font-weight: 500;
}
.nav-item--active:hover { background: var(--color-primary-dark); }

/* Shared icon + label styles */
.nav-icon {
    flex-shrink: 0;
    width: 1.1rem;
    text-align: center;
    opacity: 0.85;
}

.nav-icon svg,
.logout-icon svg {
    display: block;
    margin: 0 auto;
}

.nav-label {
    white-space: nowrap;
    transition: opacity 0.15s;
}

/* Site group: collapsible container */
.nav-sub-list {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.25s ease;
}
.nav-site-group--open .nav-sub-list {
    max-height: 400px;
}

.nav-site {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    color: #94a3b8;
    background: none;
    border: none;
    text-align: left;
    text-decoration: none;
    padding: 0.4rem 1rem 0.4rem 1.25rem;
    font-size: 0.875rem;
    font-family: inherit;
    transition: color 0.12s;
    cursor: pointer;
}

.nav-site:hover { color: #e2e8f0; }

.nav-site--active {
    color: #e2e8f0;
    font-weight: 500;
}

.nav-chevron {
    font-size: 0.65rem;
    opacity: 0.7;
    flex-shrink: 0;
    width: 0.8rem;
    text-align: center;
}

.nav-sub-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #64748b;
    text-decoration: none;
    padding: 0.3rem 1rem 0.3rem 2.35rem;
    font-size: 0.83rem;
    transition: color 0.12s, padding-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-sub-item:hover { color: #94a3b8; }

.nav-sub-item--active {
    color: #93c5fd;
    font-weight: 500;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-footer-user {
    color: #64748b;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.15s;
}

.sidebar-footer .btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.15);
    color: #94a3b8;
    font-size: 0.8rem;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
    transition: background 0.12s;
    cursor: pointer;
}

.sidebar-footer .btn-logout:hover {
    background: rgba(255,255,255,0.08);
    color: #e2e8f0;
}

.logout-icon { display: none; font-size: 1rem; }
.logout-label { white-space: nowrap; }

.sidebar-content {
    margin-left: 220px;
    padding: 2rem 1.5rem;
    min-width: 0;
    flex: 1;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .sidebar-content {
    margin-left: 56px;
}

/* Sidebar divider between nav sections */
.nav-divider {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.07);
    margin: 0.5rem 0;
}

/* ---------------------------------------------------------------------------
   Collapsed sidebar — centre all icons, hide labels
--------------------------------------------------------------------------- */

/* Logo: hide text, keep ⚡ icon */
body.sidebar-collapsed .sidebar-logo                    { justify-content: center; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .sidebar-logo-text               { opacity: 0; width: 0; overflow: hidden; }
body.sidebar-collapsed .sidebar:hover .sidebar-logo     { justify-content: flex-start; padding-left: 1rem; padding-right: 1rem; }
body.sidebar-collapsed .sidebar:hover .sidebar-logo-text { opacity: 1; width: auto; overflow: visible; }

/* Collapse labels to zero width so they don't consume flex space */
body.sidebar-collapsed .nav-label   { opacity: 0; width: 0; overflow: hidden; }

/* Restore labels on hover */
body.sidebar-collapsed .sidebar:hover .nav-label   { opacity: 1; width: auto; overflow: visible; }

/* Chevron stays visible — it is the icon for site rows.
   Make it slightly larger so it reads well in the 56px strip. */
body.sidebar-collapsed .nav-chevron { font-size: 0.8rem; }
body.sidebar-collapsed .sidebar:hover .nav-chevron { font-size: 0.65rem; }

/* All nav rows: gap 0 + centre so the lone icon sits mid-strip */
body.sidebar-collapsed .nav-item {
    gap: 0;
    justify-content: center;
    padding: 0.45rem 0;
    margin: 0;
    border-radius: 0;
}
body.sidebar-collapsed .nav-site     { gap: 0; justify-content: center; padding: 0.4rem 0; }
body.sidebar-collapsed .nav-sub-item { gap: 0; justify-content: center; padding: 0.4rem 0; }

/* Restore full layout on hover */
body.sidebar-collapsed .sidebar:hover .nav-item {
    gap: 0.65rem;
    justify-content: flex-start;
    padding: 0.45rem 1rem;
    margin: 0 0.5rem;
    border-radius: 4px;
}
body.sidebar-collapsed .sidebar:hover .nav-site     { gap: 0.4rem; justify-content: flex-start; padding: 0.4rem 1rem 0.4rem 1.25rem; }
body.sidebar-collapsed .sidebar:hover .nav-sub-item { gap: 0.6rem; justify-content: flex-start; padding: 0.3rem 1rem 0.3rem 2.35rem; }

/* Section label (SITES) */
body.sidebar-collapsed .nav-section-label               { opacity: 0; padding-top: 0.3rem; padding-bottom: 0.3rem; }
body.sidebar-collapsed .sidebar:hover .nav-section-label { opacity: 1; padding-top: 0.9rem; padding-bottom: 0.3rem; }

/* Hide sidebar-nav scrollbar when collapsed; restore on hover */
body.sidebar-collapsed .sidebar-nav                     { overflow: hidden; }
body.sidebar-collapsed .sidebar:hover .sidebar-nav      { overflow-y: auto; }

/* Footer: centre and hide username */
body.sidebar-collapsed .sidebar-footer                  { align-items: center; padding: 0.9rem 0; }
body.sidebar-collapsed .sidebar-footer-user             { opacity: 0; height: 0; overflow: hidden; }
body.sidebar-collapsed .sidebar:hover .sidebar-footer   { align-items: stretch; padding: 0.9rem 1rem; }
body.sidebar-collapsed .sidebar:hover .sidebar-footer-user { opacity: 1; height: auto; overflow: visible; }

/* Logout: show ← arrow only, centred */
body.sidebar-collapsed .logout-label                    { display: none; }
body.sidebar-collapsed .logout-icon                     { display: block; }
body.sidebar-collapsed .sidebar:hover .logout-label     { display: block; }
body.sidebar-collapsed .sidebar:hover .logout-icon      { display: none; }

/* ---------------------------------------------------------------------------
   Sidebar toggle button (floats at sidebar right edge)
--------------------------------------------------------------------------- */
.sidebar-toggle {
    position: fixed;
    top: 50px;
    left: 208px;          /* 220 - 12: centred on right edge */
    width: 24px;
    height: 24px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 50%;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 101;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1), background 0.15s, color 0.15s;
    font-size: 13px;
    line-height: 1;
}

.sidebar-toggle:hover {
    background: #334155;
    color: #e2e8f0;
}

.sidebar-toggle-icon {
    display: inline-block;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    /* ‹ points left (expanded = hide). Rotated = › (collapsed = show) */
}

body.sidebar-collapsed .sidebar-toggle {
    left: 44px;           /* 56 - 12 */
}

body.sidebar-collapsed .sidebar-toggle-icon {
    transform: rotate(180deg);
}

/* ---------------------------------------------------------------------------
   Sidebar backdrop (mobile overlay close)
--------------------------------------------------------------------------- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 98;
}

/* ---------------------------------------------------------------------------
   Responsive — mobile (< 768 px)
--------------------------------------------------------------------------- */
@media (max-width: 767px) {
    /* Sidebar slides in from left as overlay; never pushes content */
    .sidebar {
        width: 220px !important;
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
    }

    body.sidebar-mobile-open .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    }

    /* Disable hover-expand on touch devices */
    body.sidebar-collapsed .sidebar:hover {
        width: 220px !important;
        box-shadow: none;
    }

    /* Content always fills full width on mobile */
    .sidebar-content {
        margin-left: 0 !important;
        padding: 1.25rem 1rem;
        transition: none;
    }

    /* Toggle button: top-left corner when sidebar is hidden */
    .sidebar-toggle {
        left: 12px;
        top: 50px;
        transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    body.sidebar-mobile-open .sidebar-toggle {
        left: 208px;
    }

    /* Rotate icon: on mobile, closed = ›, open = ‹ */
    .sidebar-toggle-icon {
        transform: rotate(180deg);
    }

    body.sidebar-mobile-open .sidebar-toggle-icon {
        transform: rotate(0deg);
    }

    body.sidebar-mobile-open .sidebar-backdrop {
        display: block;
    }
}
