@import './tokens.css';

/* ── App shell ─────────────────────────────────────────────── */

.hd-app {
    min-height: 100vh;
    display: flex;
}

.hd-sidebar {
    width: var(--hd-sidebar-width);
    min-height: 100vh;
    background: var(--hd-sidebar-gradient, var(--hd-sidebar-bg));
    color: var(--hd-sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1030;
    transition: width 0.2s ease, transform 0.2s ease;
    border-right: 1px solid rgb(255 255 255 / 0.06);
}

.hd-app.sidebar-collapsed .hd-sidebar {
    width: var(--hd-sidebar-collapsed-width);
}

.hd-sidebar-brand {
    height: var(--hd-topbar-height);
    display: flex;
    align-items: center;
    padding: 0 var(--hd-space-4);
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgb(255 255 255 / 0.06);
    overflow: hidden;
    flex-shrink: 0;
}

.hd-sidebar-brand:hover { color: #fff; }

.hd-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--hd-space-3) var(--hd-space-2);
}

.hd-nav-section {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--hd-sidebar-muted);
    padding: var(--hd-space-4) var(--hd-space-3) var(--hd-space-2);
}

.hd-app.sidebar-collapsed .hd-nav-section,
.hd-app.sidebar-collapsed .hd-nav-label,
.hd-app.sidebar-collapsed .hd-sidebar-brand span {
    display: none;
}

.hd-app.sidebar-collapsed .hd-sidebar-brand {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.hd-app.sidebar-collapsed .hd-nav-link {
    justify-content: center;
    padding-left: 0.625rem;
    padding-right: 0.625rem;
}

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

.hd-sidebar-toggle-icon {
    transition: transform 0.2s ease;
}

.hd-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgb(15 23 42 / 0.45);
    z-index: 1025;
}

.hd-sidebar-backdrop:not([hidden]) {
    display: block;
}

.hd-nav-link {
    display: flex;
    align-items: center;
    gap: var(--hd-space-3);
    padding: 0.625rem var(--hd-space-3);
    margin-bottom: 2px;
    border-radius: var(--hd-radius-md);
    color: var(--hd-sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background 0.15s ease;
}

.hd-nav-link:hover {
    background: rgb(255 255 255 / 0.06);
    color: #fff;
}

.hd-nav-link.active {
    background: var(--hd-sidebar-active);
    color: #fff;
}

.hd-nav-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    opacity: 0.85;
}

.hd-main {
    flex: 1;
    margin-left: var(--hd-sidebar-width);
    min-width: 0;
    transition: margin-left 0.2s ease;
}

.hd-app.sidebar-collapsed .hd-main {
    margin-left: var(--hd-sidebar-collapsed-width);
}

.hd-topbar {
    height: var(--hd-topbar-height);
    background: var(--hd-surface);
    border-bottom: 1px solid var(--hd-border);
    display: flex;
    align-items: center;
    padding: 0 var(--hd-space-4);
    gap: var(--hd-space-3);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.hd-topbar-search {
    flex: 1;
    max-width: 28rem;
    position: relative;
}

.hd-topbar-search input {
    width: 100%;
    padding: 0.5rem 0.875rem 0.5rem 2.25rem;
    border: 1px solid var(--hd-border);
    border-radius: var(--hd-radius-lg);
    background: var(--hd-bg);
    color: var(--hd-text);
    font-size: 0.875rem;
}

.hd-topbar-search input:focus {
    outline: 2px solid rgb(var(--hd-primary-rgb) / 0.35);
    border-color: var(--hd-primary);
}

.hd-topbar-search kbd {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6875rem;
    padding: 0.125rem 0.375rem;
    border-radius: var(--hd-radius-sm);
    background: var(--hd-surface);
    border: 1px solid var(--hd-border);
    color: var(--hd-text-muted);
}

.hd-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
    color: var(--hd-text-muted);
    pointer-events: none;
}

.hd-content {
    padding: var(--hd-space-6) var(--hd-space-6) var(--hd-space-10);
    max-width: 1440px;
}

/* ── Page header ───────────────────────────────────────────── */

.hd-page-header {
    margin-bottom: var(--hd-space-6);
}

.hd-page-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 var(--hd-space-1);
    color: var(--hd-text);
}

.hd-page-subtitle {
    color: var(--hd-text-secondary);
    font-size: 0.9375rem;
    margin: 0;
}

/* ── Stat cards ────────────────────────────────────────────── */

.hd-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: var(--hd-space-4);
    margin-bottom: var(--hd-space-6);
}

.hd-stat-card {
    background: var(--hd-surface);
    border: 1px solid var(--hd-border);
    border-radius: var(--hd-radius-lg);
    padding: var(--hd-space-5);
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    display: block;
}

.hd-stat-card:hover {
    box-shadow: var(--hd-shadow-md);
    border-color: rgb(var(--hd-primary-rgb) / 0.35);
    color: inherit;
}

.hd-stat-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--hd-text-secondary);
    margin-bottom: var(--hd-space-2);
}

.hd-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.hd-stat-card.danger .hd-stat-value { color: var(--hd-danger); }
.hd-stat-card.warning .hd-stat-value { color: var(--hd-warning); }

/* ── Status & priority badges ──────────────────────────────── */

.hd-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.hd-badge-dot {
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background: currentColor;
}

.hd-badge-neutral { background: var(--hd-border-subtle); color: var(--hd-text-secondary); }
.hd-badge-open { background: var(--hd-info-soft); color: var(--hd-info); }
.hd-badge-progress { background: var(--hd-primary-soft); color: var(--hd-primary); }
.hd-badge-waiting { background: var(--hd-warning-soft); color: var(--hd-warning); }
.hd-badge-resolved { background: var(--hd-success-soft); color: var(--hd-success); }
.hd-badge-closed { background: var(--hd-border-subtle); color: var(--hd-text-muted); }
.hd-badge-danger { background: var(--hd-danger-soft); color: var(--hd-danger); }

.hd-priority-low { color: var(--hd-text-muted); }
.hd-priority-medium { color: var(--hd-info); font-weight: 600; }
.hd-priority-high { color: var(--hd-warning); font-weight: 600; }
.hd-priority-urgent { color: var(--hd-danger); font-weight: 700; }

/* ── Quick views (ticket list tabs) ────────────────────────── */

.hd-quick-views {
    display: flex;
    flex-wrap: wrap;
    gap: var(--hd-space-2);
    margin-bottom: var(--hd-space-4);
}

.hd-quick-view {
    padding: 0.375rem 0.875rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid var(--hd-border);
    background: var(--hd-surface);
    color: var(--hd-text-secondary);
    text-decoration: none;
    transition: all 0.15s ease;
}

.hd-quick-view:hover,
.hd-quick-view.active {
    border-color: var(--hd-primary);
    background: var(--hd-primary-soft);
    color: var(--hd-primary);
}

/* ── Empty state ───────────────────────────────────────────── */

.hd-empty {
    text-align: center;
    padding: var(--hd-space-10) var(--hd-space-6);
}

.hd-empty-icon {
    font-size: 2.5rem;
    margin-bottom: var(--hd-space-4);
    line-height: 1;
}

.hd-empty-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: var(--hd-space-2);
}

.hd-empty-text {
    color: var(--hd-text-secondary);
    max-width: 24rem;
    margin: 0 auto var(--hd-space-5);
}

/* ── Global search dropdown ────────────────────────────────── */

.hd-search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--hd-surface);
    border: 1px solid var(--hd-border);
    border-radius: var(--hd-radius-lg);
    box-shadow: var(--hd-shadow-md);
    max-height: 24rem;
    overflow-y: auto;
    display: none;
    z-index: 1050;
}

.hd-search-results.open { display: block; }

.hd-search-group-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--hd-text-muted);
    padding: var(--hd-space-3) var(--hd-space-4) var(--hd-space-1);
}

.hd-search-item {
    display: block;
    padding: var(--hd-space-3) var(--hd-space-4);
    text-decoration: none;
    color: var(--hd-text);
    border-bottom: 1px solid var(--hd-border-subtle);
}

.hd-search-item:hover { background: var(--hd-bg); color: var(--hd-text); }

.hd-search-item-sub {
    font-size: 0.8125rem;
    color: var(--hd-text-secondary);
}

/* ── Portal layout ─────────────────────────────────────────── */

.hd-portal-app .hd-content {
    max-width: 72rem;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 991.98px) {
    .hd-sidebar {
        transform: translateX(-100%);
        box-shadow: var(--hd-shadow-md);
    }

    .hd-app.sidebar-mobile-open .hd-sidebar {
        transform: translateX(0);
    }

    .hd-main {
        margin-left: 0 !important;
    }

    .hd-topbar-search { max-width: none; }

    .hd-topbar-search kbd { display: none; }
}

@media (max-width: 575.98px) {
    .hd-content {
        padding: var(--hd-space-4);
    }

    .hd-stat-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── Buttons refinement ────────────────────────────────────── */

.btn-primary {
    background: var(--hd-primary-gradient, var(--hd-primary));
    border-color: transparent;
}

.btn-primary:hover {
    background: var(--hd-primary-hover);
    border-color: var(--hd-primary-hover);
    filter: brightness(1.05);
}

.btn-outline-primary {
    color: var(--hd-primary);
    border-color: var(--hd-primary);
}

.btn-outline-primary:hover {
    background: var(--hd-primary-soft);
}

/* ── Table improvements ────────────────────────────────────── */

.hd-table-wrap .table thead th {
    position: sticky;
    top: 0;
    background: var(--hd-surface);
    z-index: 1;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--hd-text-secondary);
    border-bottom-width: 1px;
}

.hd-table-wrap tbody tr:hover {
    background: var(--hd-bg);
}

[data-density="compact"] .table td,
[data-density="compact"] .table th {
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
}

/* ── Toast ─────────────────────────────────────────────────── */

.hd-toast {
    position: fixed;
    bottom: var(--hd-space-6);
    right: var(--hd-space-6);
    background: var(--hd-surface);
    border: 1px solid var(--hd-border);
    box-shadow: var(--hd-shadow-md);
    border-radius: var(--hd-radius-lg);
    padding: var(--hd-space-4) var(--hd-space-5);
    z-index: 2000;
    animation: hd-fade-in 0.2s ease;
}

@keyframes hd-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Preferences swatches ──────────────────────────────────── */

.hd-corporate-palette {
    display: flex;
    height: 0.625rem;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--hd-border);
    max-width: 20rem;
}

.hd-corporate-palette-segment {
    flex: 1 1 20%;
    min-width: 0;
}

.hd-accent-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
}

.hd-accent-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    min-width: 4.5rem;
    cursor: pointer;
    margin: 0;
}

.hd-accent-swatch {
    display: block;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: 2px solid var(--hd-border);
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: var(--hd-shadow-sm);
}

.hd-accent-swatch.selected {
    border-color: var(--hd-text);
    box-shadow: 0 0 0 2px var(--hd-surface), 0 0 0 4px var(--hd-primary);
}

.hd-accent-label {
    font-size: 0.6875rem;
    line-height: 1.2;
    text-align: center;
    color: var(--hd-text-secondary);
    max-width: 4.75rem;
}

.swatch-dsl-gradient { background: linear-gradient(135deg, #1a5daa 0%, #1f4e79 52%, #164f92 100%); }
.swatch-dsl-blue { background: #1a5daa; }
.swatch-dsl-red { background: #e1251b; }
.swatch-dsl-orange { background: #f18a21; }
.swatch-dsl-terracotta { background: #af3e2d; }
.swatch-dsl-bronze { background: #8b6638; }
.swatch-dsl-navy { background: #1f4e79; }

/* ── Brand logos (fixed placeholders; image scales inside) ─── */

.hd-brand-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.hd-brand-slot--site {
    width: 180px;
    height: 36px;
    justify-content: flex-start;
}

.hd-brand-slot--login {
    width: 240px;
    height: 100px;
}

.hd-brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

.hd-app.sidebar-collapsed .hd-brand-slot--site {
    width: 36px;
    height: 36px;
    justify-content: center;
}

.navbar-brand .hd-brand-slot--site {
    justify-content: flex-start;
}

/* Inset panels (KB snippets, callouts) — theme-aware, never hard-coded white */
.hd-inset-panel {
    background: var(--hd-surface-elevated);
    border-color: var(--hd-border) !important;
    color: var(--hd-text);
}

.hd-inset-panel .text-secondary {
    color: var(--hd-text-secondary) !important;
}
