/* ==========================================================================
   Dashboard UI refresh
   --------------------------------------------------------------------------
   Loaded after main.css. Like landing.css this themes by token and lays out
   with logical properties, so RTL and LTR both come from one source.
   ========================================================================== */

:root {
    --dsh-radius: 12px;
    --dsh-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --dsh-bg: #FFFFFF;
    --dsh-surface: #FFFFFF;
    --dsh-surface-2: #F7F6F2;
    --dsh-border: #E7E4DB;
    --dsh-text: #0F221A;
    --dsh-text-soft: #46564E;
    --dsh-text-muted: #7A8781;
    --dsh-accent: #8A6D14;
    --dsh-accent-soft: rgba(138, 109, 20, 0.09);
    --dsh-danger: #B3261E;
    --dsh-danger-soft: rgba(179, 38, 30, 0.09);
    --dsh-shadow: 0 4px 12px rgba(15, 34, 26, 0.06), 0 12px 32px rgba(15, 34, 26, 0.06);
}
html[data-theme="dark"] {
    --dsh-bg: #0B1A14;
    --dsh-surface: #0E211A;
    --dsh-surface-2: #12281F;
    --dsh-border: rgba(201, 162, 39, 0.16);
    --dsh-text: #F4F2EA;
    --dsh-text-soft: rgba(244, 242, 234, 0.74);
    --dsh-text-muted: rgba(244, 242, 234, 0.5);
    --dsh-accent: #C9A227;
    --dsh-accent-soft: rgba(201, 162, 39, 0.12);
    --dsh-danger: #F2705F;
    --dsh-danger-soft: rgba(242, 112, 95, 0.14);
    --dsh-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   Topbar cluster — language, theme, notifications and the account menu
   all live here now instead of being buried in the sidebar footer.
   ========================================================================== */

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tb-btn {
    inline-size: 38px;
    block-size: 38px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    border: 1px solid var(--dsh-border);
    background: var(--dsh-surface-2);
    color: var(--dsh-text-soft);
    cursor: pointer;
    position: relative;
    transition: color 0.2s var(--dsh-ease), border-color 0.2s var(--dsh-ease), transform 0.2s var(--dsh-ease);
}
.tb-btn:hover { color: var(--dsh-accent); border-color: var(--dsh-accent); transform: translateY(-1px); }
.tb-btn:focus-visible { outline: 2px solid var(--dsh-accent); outline-offset: 2px; }
.tb-dot {
    position: absolute;
    inset-block-start: 8px;
    inset-inline-end: 9px;
    inline-size: 8px;
    block-size: 8px;
    border-radius: 50%;
    background: var(--dsh-danger);
    border: 2px solid var(--dsh-surface-2);
}

/* Language bar — fixed-size buttons so switching cannot reflow the topbar */
.tb-langbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 12px;
    background: var(--dsh-surface-2);
    border: 1px solid var(--dsh-border);
    flex: none;
}
.tb-lang {
    inline-size: 32px;
    block-size: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--dsh-text-muted);
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: color 0.2s var(--dsh-ease), background-color 0.2s var(--dsh-ease);
}
.tb-lang:hover { color: var(--dsh-text); background: var(--dsh-accent-soft); }
.tb-lang.is-active { color: #fff; background: var(--dsh-accent); }
html[data-theme="dark"] .tb-lang.is-active { color: #0B1A14; }

/* Account menu */
.tb-account { position: relative; }
.tb-account-btn {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 5px 10px 5px 5px;
    border-radius: 40px;
    border: 1px solid var(--dsh-border);
    background: var(--dsh-surface-2);
    color: var(--dsh-text);
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s var(--dsh-ease);
}
.tb-account-btn:hover { border-color: var(--dsh-accent); }
.tb-avatar {
    inline-size: 30px;
    block-size: 30px;
    flex: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--dsh-accent);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
}
html[data-theme="dark"] .tb-avatar { color: #0B1A14; }
.tb-account-name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    max-inline-size: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tb-caret { transition: transform 0.2s var(--dsh-ease); flex: none; }
.tb-account.is-open .tb-caret { transform: rotate(180deg); }

.tb-menu {
    position: absolute;
    inset-block-start: calc(100% + 8px);
    inset-inline-end: 0;
    min-inline-size: 232px;
    background: var(--dsh-surface);
    border: 1px solid var(--dsh-border);
    border-radius: var(--dsh-radius);
    box-shadow: var(--dsh-shadow);
    padding: 6px;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.18s var(--dsh-ease), transform 0.18s var(--dsh-ease), visibility 0.18s;
}
.tb-account.is-open .tb-menu { opacity: 1; visibility: visible; transform: none; }
.tb-menu-head { padding: 10px 12px 12px; border-block-end: 1px solid var(--dsh-border); margin-block-end: 6px; }
.tb-menu-name { font-size: 14px; font-weight: 700; color: var(--dsh-text); }
.tb-menu-mail { font-size: 12px; color: var(--dsh-text-muted); direction: ltr; text-align: start; word-break: break-all; }
.tb-menu-role {
    display: inline-block;
    margin-block-start: 7px;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 20px;
    background: var(--dsh-accent-soft);
    color: var(--dsh-accent);
}
.tb-menu a, .tb-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    inline-size: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--dsh-text-soft);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    text-align: start;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s var(--dsh-ease), color 0.15s var(--dsh-ease);
}
.tb-menu a:hover, .tb-menu button:hover { background: var(--dsh-accent-soft); color: var(--dsh-accent); }
.tb-menu .tb-menu-danger:hover { background: var(--dsh-danger-soft); color: var(--dsh-danger); }
/* Chevrons and arrows must point the way the language reads. */
.tb-menu a svg, .tb-menu button svg { flex: none; }
html[dir="rtl"] .dsh-flip { transform: scaleX(-1); }

/* ==========================================================================
   Stat cards — five across on one row
   ========================================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
}
.stats-grid > .stat-card { min-inline-size: 0; }
/* Layouts with four or fewer cards keep comfortable widths. */
.stats-grid:has(> .stat-card:last-child:nth-child(4)) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stats-grid:has(> .stat-card:last-child:nth-child(3)) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats-grid:has(> .stat-card:last-child:nth-child(2)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 1100px) { .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px)  { .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 440px)  { .stats-grid { grid-template-columns: 1fr; } }

/* ==========================================================================
   Role badges — a role is not a status, so it gets its own scale
   ========================================================================== */

.role-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 11px;
    border-radius: 20px;
    white-space: nowrap;
    border: 1px solid transparent;
}
.role-admin  { background: rgba(138, 109, 20, 0.12); color: #7A5F10; border-color: rgba(138, 109, 20, 0.25); }
.role-agent  { background: rgba(27, 67, 50, 0.10);  color: #1B4332; border-color: rgba(27, 67, 50, 0.22); }
.role-client { background: rgba(90, 106, 99, 0.12); color: #46564E; border-color: rgba(90, 106, 99, 0.22); }
html[data-theme="dark"] .role-admin  { background: rgba(201,162,39,0.16); color: #E0B93C; border-color: rgba(201,162,39,0.35); }
html[data-theme="dark"] .role-agent  { background: rgba(120,200,160,0.14); color: #8FD8B4; border-color: rgba(120,200,160,0.3); }
html[data-theme="dark"] .role-client { background: rgba(244,242,234,0.10); color: rgba(244,242,234,0.75); border-color: rgba(244,242,234,0.2); }

/* ==========================================================================
   Form controls
   ========================================================================== */

.form-select, select.form-select {
    appearance: none;
    -webkit-appearance: none;
    padding-block: 8px;
    padding-inline: 12px 32px;
    border: 1px solid var(--dsh-border);
    border-radius: 10px;
    background-color: var(--dsh-surface);
    color: var(--dsh-text);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.3;
    cursor: pointer;
    /* Caret drawn inline so it can be placed with a logical offset and follow
       the theme colour — a background-image arrow cannot do either. */
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    transition: border-color 0.2s var(--dsh-ease), box-shadow 0.2s var(--dsh-ease);
}
html[dir="rtl"] .form-select { background-position: left 14px top 52%, left 9px top 52%; }
html[dir="ltr"] .form-select { background-position: right 14px top 52%, right 9px top 52%; }
.form-select:hover { border-color: var(--dsh-accent); }
.form-select:focus {
    outline: none;
    border-color: var(--dsh-accent);
    box-shadow: 0 0 0 3px var(--dsh-accent-soft);
}

/* Checkbox / permission toggle */
.perm-toggle input[type="checkbox"],
.dsh-check input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    inline-size: 20px;
    block-size: 20px;
    margin: 0;
    border: 2px solid var(--dsh-border);
    border-radius: 6px;
    background: var(--dsh-surface);
    cursor: pointer;
    position: relative;
    transition: background-color 0.18s var(--dsh-ease), border-color 0.18s var(--dsh-ease);
}
.perm-toggle input[type="checkbox"]:hover,
.dsh-check input[type="checkbox"]:hover { border-color: var(--dsh-accent); }
.perm-toggle input[type="checkbox"]:checked,
.dsh-check input[type="checkbox"]:checked { background: var(--dsh-accent); border-color: var(--dsh-accent); }
.perm-toggle input[type="checkbox"]:checked::after,
.dsh-check input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    inset-block-start: 1px;
    inset-inline-start: 5px;
    inline-size: 5px;
    block-size: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
html[data-theme="dark"] .perm-toggle input[type="checkbox"]:checked::after,
html[data-theme="dark"] .dsh-check input[type="checkbox"]:checked::after { border-color: #0B1A14; }
.perm-toggle input[type="checkbox"]:focus-visible,
.dsh-check input[type="checkbox"]:focus-visible { outline: 2px solid var(--dsh-accent); outline-offset: 2px; }

.dsh-check {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--dsh-text-soft);
    user-select: none;
}

/* ==========================================================================
   Table row actions — icon buttons instead of stacked text buttons
   ========================================================================== */

.row-actions { display: inline-flex; align-items: center; gap: 6px; }
.icon-btn {
    inline-size: 32px;
    block-size: 32px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--dsh-border);
    border-radius: 9px;
    background: var(--dsh-surface);
    color: var(--dsh-text-muted);
    cursor: pointer;
    transition: color 0.18s var(--dsh-ease), border-color 0.18s var(--dsh-ease),
                background-color 0.18s var(--dsh-ease), transform 0.18s var(--dsh-ease);
}
.icon-btn:hover {
    color: var(--dsh-accent);
    border-color: var(--dsh-accent);
    background: var(--dsh-accent-soft);
    transform: translateY(-1px);
}
.icon-btn-danger:hover { color: var(--dsh-danger); border-color: var(--dsh-danger); background: var(--dsh-danger-soft); }
.icon-btn:focus-visible { outline: 2px solid var(--dsh-accent); outline-offset: 2px; }

/* Clickable table rows replace a per-row "view" column. */
.data-table tbody tr.row-link { cursor: pointer; transition: background-color 0.15s var(--dsh-ease); }
.data-table tbody tr.row-link:hover { background: var(--dsh-accent-soft); }

/* ==========================================================================
   Modal — direction-correct and themed
   ========================================================================== */

.modal, .modal-overlay { direction: inherit; }
.modal-content, .modal-box {
    text-align: start;
    background: var(--dsh-surface);
    color: var(--dsh-text);
    border: 1px solid var(--dsh-border);
    border-radius: 16px;
}
.modal-content .form-label, .modal-box .form-label { text-align: start; display: block; }
.modal-footer, .modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

@media (max-width: 700px) {
    .tb-account-name { display: none; }
    .tb-account-btn { padding: 5px; }
    .topbar-actions { gap: 6px; }
    .tb-lang { inline-size: 28px; }
}

/* ==========================================================================
   Sidebar brand mark (same inline SVG component as the landing page)
   ========================================================================== */

.sidebar .lp-brand-mark {
    block-size: 30px;
    inline-size: auto;
    aspect-ratio: 320 / 465;
    flex: none;
    overflow: visible;
    color: #C9A227;                 /* sidebar is dark by default */
}
html[data-theme="light"] .sidebar .lp-brand-mark { color: #1B4332; }

/* ==========================================================================
   Dialogs — inherit page direction, start-aligned, themed surface
   ========================================================================== */

.dsh-modal { direction: inherit; }
.dsh-modal-box {
    direction: inherit;
    text-align: start;
    background: var(--dsh-surface);
    color: var(--dsh-text);
    border: 1px solid var(--dsh-border);
    border-radius: 16px;
    max-block-size: 90vh;
    overflow-y: auto;
    box-shadow: var(--dsh-shadow);
}
.dsh-modal-box label { text-align: start; display: block; }
.dsh-modal-box .form-control,
.dsh-modal-box .form-select { inline-size: 100%; text-align: start; }
/* Email and phone stay LTR even in an RTL dialog, but must still sit on the
   reading edge — text-align:start with dir=ltr would push them the wrong way. */
html[dir="rtl"] .dsh-modal-box input[dir="ltr"] { text-align: right; }
html[dir="ltr"] .dsh-modal-box input[dir="ltr"] { text-align: left; }

.role-form { display: flex; gap: 6px; align-items: center; }
.role-form .form-select { inline-size: auto; min-inline-size: 118px; font-size: 12px; padding-block: 6px; }

/* ==========================================================================
   Sidebar header / topbar alignment
   The sidebar brand was sized by its padding and the topbar by its own, so the
   two bottom borders never met. One shared height lines them up.
   ========================================================================== */

:root { --dsh-bar-h: 74px; }

.topbar {
    min-block-size: var(--dsh-bar-h);
    padding-block: 0;
}
.sidebar-brand {
    min-block-size: var(--dsh-bar-h);
    padding-block: 0;
    display: flex;
    align-items: center;
}
.sidebar-brand > a { inline-size: 100%; }
/* Flex centres boxes, not glyphs: without an explicit line-height the two-line
   brand block sat low next to the mark. */
.sidebar-brand > a > div { display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.sidebar-brand > a > div > div { line-height: 1.25; }

@media (max-width: 900px) {
    :root { --dsh-bar-h: 64px; }
}

/* Sidebar brand: the mark and the wordmark on one optical baseline. The old
   markup relied on default line-heights, so the two-line text block sat low
   next to the mark. */
.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: 11px;
    text-decoration: none;
    min-inline-size: 0;
}
.sidebar-brand-text { display: flex; flex-direction: column; justify-content: center; gap: 3px; min-inline-size: 0; }
.sidebar-brand-name {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    color: #C9A227;
    white-space: nowrap;
}
.sidebar-brand-tag {
    font-size: 10px;
    line-height: 1.3;
    color: rgba(255, 255, 255, 0.42);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
html[data-theme="light"] .sidebar-brand-name { color: #1B4332; }
html[data-theme="light"] .sidebar-brand-tag { color: #8A9691; }

/* ==========================================================================
   Dark theme for the dashboard shell
   main.css defines light values on :root and overrides them again under
   [data-theme="light"] — but never for dark, so the content area stayed white
   behind a dark sidebar and topbar. These fill that gap.
   ========================================================================== */

html[data-theme="dark"] .main-content,
html[data-theme="dark"] .page-content { background: var(--dsh-bg); color: var(--dsh-text); }

html[data-theme="dark"] .topbar {
    background: var(--dsh-surface);
    border-bottom-color: var(--dsh-border);
}
html[data-theme="dark"] .topbar-title h1 { color: var(--dsh-text); }
html[data-theme="dark"] .topbar-title p { color: var(--dsh-text-muted); }

html[data-theme="dark"] .card,
html[data-theme="dark"] .stat-card {
    background: var(--dsh-surface);
    border-color: var(--dsh-border);
    color: var(--dsh-text);
}
html[data-theme="dark"] .card-header {
    background: transparent;
    border-bottom-color: var(--dsh-border);
}
html[data-theme="dark"] .card-header h3 { color: var(--dsh-text); }
html[data-theme="dark"] .stat-value { color: var(--dsh-text); }
html[data-theme="dark"] .stat-label { color: var(--dsh-text-muted); }

html[data-theme="dark"] .data-table th {
    background: var(--dsh-surface-2);
    color: var(--dsh-text-muted);
    border-bottom-color: var(--dsh-border);
}
html[data-theme="dark"] .data-table td {
    color: var(--dsh-text);
    border-bottom-color: var(--dsh-border);
}
html[data-theme="dark"] .data-table tbody tr:hover { background: var(--dsh-accent-soft); }
html[data-theme="dark"] .table-wrap { border-color: var(--dsh-border); }
html[data-theme="dark"] .empty-state { color: var(--dsh-text-muted); }
html[data-theme="dark"] .empty-state h4 { color: var(--dsh-text); }

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background: var(--dsh-surface-2);
    border-color: var(--dsh-border);
    color: var(--dsh-text);
}
html[data-theme="dark"] .form-control::placeholder { color: var(--dsh-text-muted); }
html[data-theme="dark"] .btn-outline {
    background: transparent;
    border-color: var(--dsh-border);
    color: var(--dsh-text-soft);
}
html[data-theme="dark"] .btn-outline:hover { border-color: var(--dsh-accent); color: var(--dsh-accent); }
html[data-theme="dark"] .btn-primary { background: var(--dsh-accent); color: #0B1A14; border-color: transparent; }

/* The sticky permissions action bar sat on the light page colour. */
html[data-theme="dark"] .page-content > form > div[style*="position: sticky"] {
    background: var(--dsh-bg) !important;
    border-top-color: var(--dsh-border) !important;
}
