/* ==========================================================================
   SmartFluent Dashboard (V2) styles

   Mirrors the look of the old React dashboard (dashboard/src/index.css +
   shadcn UI components). Colors are HSL triplets consumed via
   hsl(var(--token) / <alpha>), with a light default theme and a `.dark`
   override toggled by the theme switcher (see /js/theme-init.js and
   /js/theme-toggle.js).
   ========================================================================== */

/* ==========================================================================
   1. Design tokens (light + dark themes)
   ========================================================================== */

:root {
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;
    --primary: 222.2 47.4% 11.2%;
    --primary-foreground: 210 40% 98%;
    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;
    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 40% 98%;
    --success: 142 71% 45%;
    --success-foreground: 210 40% 98%;
    --warning: 38 92% 50%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 222.2 84% 4.9%;

    --radius: 0.5rem;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);

    --font-sans:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
        sans-serif;
}

.dark {
    --background: 222.2 84% 4.9%;
    --foreground: 210 40% 98%;
    --card: 222.2 84% 4.9%;
    --card-foreground: 210 40% 98%;
    --popover: 222.2 84% 4.9%;
    --popover-foreground: 210 40% 98%;
    --primary: 210 40% 98%;
    --primary-foreground: 222.2 47.4% 11.2%;
    --secondary: 217.2 32.6% 17.5%;
    --secondary-foreground: 210 40% 98%;
    --muted: 217.2 32.6% 17.5%;
    --muted-foreground: 215 20.2% 65.1%;
    --accent: 217.2 32.6% 17.5%;
    --accent-foreground: 210 40% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 210 40% 98%;
    --success: 142 71% 45%;
    --success-foreground: 210 40% 98%;
    --warning: 38 92% 50%;
    --border: 217.2 32.6% 17.5%;
    --input: 217.2 32.6% 17.5%;
    --ring: 212.7 26.8% 83.9%;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
}

/* ==========================================================================
   2. Base styles
   ========================================================================== */

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

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

[x-cloak] {
    display: none !important;
}

a {
    color: hsl(var(--primary));
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.icon-sm {
    width: 1rem;
    height: 1rem;
}

/* ==========================================================================
   3. App shell / layout
   ========================================================================== */

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

.sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    width: 240px;
    height: 100vh;
    flex-shrink: 0;
    overflow-y: auto;
    background-color: hsl(var(--background));
    border-right: 1px solid hsl(var(--border));
    padding: var(--space-6) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
    font-size: 18px;
    margin-bottom: var(--space-6);
    color: hsl(var(--foreground));
}

.sidebar-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: calc(var(--radius) - 2px);
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    font-size: 13px;
    font-weight: 700;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    transition:
        background-color 0.15s ease,
        color 0.15s ease;
}

.nav-link .icon-sm {
    flex-shrink: 0;
}

.nav-link:hover {
    background-color: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
    text-decoration: none;
}

.nav-link.active {
    background-color: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding-top: var(--space-4);
}

.sidebar-user {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-footer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.sidebar-footer-actions > form,
.sidebar-footer-actions > .theme-toggle {
    display: flex;
    align-items: center;
    margin: 0;
}

.main-area {
    flex: 1;
    padding: var(--space-8);
    overflow-x: auto;
}

/* ==========================================================================
   4. Auth pages (login)
   ========================================================================== */

.auth-area {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-4);
}

.auth-card {
    width: 100%;
    max-width: 28rem;
    background-color: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6);
}

.auth-title {
    margin: 0 0 var(--space-2);
    font-size: 24px;
    font-weight: 700;
    text-align: center;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.auth-label {
    font-size: 14px;
    font-weight: 500;
    color: hsl(var(--foreground));
}

.auth-input {
    height: 40px;
    width: 100%;
    background-color: hsl(var(--background));
    border: 1px solid hsl(var(--input));
    border-radius: var(--radius);
    color: hsl(var(--foreground));
    padding: 0 var(--space-3);
    font: inherit;
}

.auth-input:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 1px hsl(var(--ring));
}

.auth-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 40px;
    width: 100%;
    margin-top: var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.auth-button:hover {
    background-color: hsl(var(--primary) / 0.9);
}

.auth-button:disabled {
    pointer-events: none;
    opacity: 0.5;
}

.auth-button-secondary {
    background-color: hsl(var(--background));
    border-color: hsl(var(--input));
    color: hsl(var(--foreground));
}

.auth-button-secondary:hover {
    background-color: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: var(--space-4) 0;
    color: hsl(var(--muted-foreground));
    font-size: 12px;
    text-transform: uppercase;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid hsl(var(--border));
}

.auth-error {
    margin: var(--space-3) 0 0;
    color: hsl(var(--destructive));
    font-size: 14px;
    text-align: center;
}

/* ==========================================================================
   5. Typography / page structure
   ========================================================================== */

.page {
    display: block;
}

.page-title {
    margin: 0 0 var(--space-6) 0;
    font-size: 24px;
    font-weight: 700;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.page-header .page-title {
    margin: 0;
}

.page-description {
    color: hsl(var(--muted-foreground));
    margin-bottom: var(--space-4);
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin: var(--space-6) 0 var(--space-4);
}

/* ==========================================================================
   6. Cards
   ========================================================================== */

.card {
    background-color: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.card-link {
    display: block;
    color: inherit;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.card-link:hover {
    border-color: hsl(var(--ring));
    box-shadow: var(--shadow-md);
    text-decoration: none;
}

.nav-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    min-height: 168px;
    text-align: center;
}

.nav-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: var(--radius);
    background-color: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    transition:
        background-color 0.15s ease,
        color 0.15s ease;
}

.nav-card-icon .icon-sm {
    width: 2rem;
    height: 2rem;
}

.nav-card:hover .nav-card-icon {
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.nav-card-label {
    font-size: 18px;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.card-label {
    font-size: 13px;
    color: hsl(var(--muted-foreground));
}

.card-value {
    font-size: 28px;
    font-weight: 700;
    margin-top: var(--space-2);
}

.card-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

/* ==========================================================================
   7. Forms
   ========================================================================== */

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: flex-end;
    margin-bottom: var(--space-6);
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.label {
    font-size: 13px;
    font-weight: 500;
    color: hsl(var(--foreground));
}

.input,
.select,
.textarea {
    background-color: hsl(var(--background));
    border: 1px solid hsl(var(--input));
    border-radius: var(--radius);
    color: hsl(var(--foreground));
    padding: var(--space-2) var(--space-3);
    font: inherit;
    width: 100%;
}

.textarea {
    min-height: 96px;
    resize: vertical;
}

/* Replace the native dropdown arrow (which hugs the right border) with a
   CSS-gradient chevron set in from the edge. Gradients are used instead of a
   background image so it stays within the strict CSP and adapts to the theme
   via the --muted-foreground token. */
.select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: var(--space-8);
    background-image:
        linear-gradient(
            45deg,
            transparent 50%,
            hsl(var(--muted-foreground)) 50%
        ),
        linear-gradient(
            135deg,
            hsl(var(--muted-foreground)) 50%,
            transparent 50%
        );
    background-position:
        calc(100% - 18px) center,
        calc(100% - 13px) center;
    background-size:
        5px 5px,
        5px 5px;
    background-repeat: no-repeat;
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 1px hsl(var(--ring));
}

.input::placeholder,
.textarea::placeholder {
    color: hsl(var(--muted-foreground));
}

.field-error {
    color: hsl(var(--destructive));
    font-size: 13px;
    margin: 0;
}

.field-hint {
    margin-top: var(--space-2);
    color: hsl(var(--muted-foreground));
    font-size: 0.85rem;
}

.form-error {
    color: hsl(var(--destructive));
    margin: var(--space-3) 0;
}

/* Scorecard form (full page) */

.scorecard-back {
    margin-bottom: var(--space-4);
}

.scorecard-form-heading {
    margin-bottom: var(--space-6);
}

.scorecard-form-heading .page-title {
    margin: 0 0 var(--space-2) 0;
}

.scorecard-form-heading .page-description {
    margin: 0;
}

.scorecard-id-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.scorecard-id-label {
    font-size: 12px;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
}

.scorecard-id-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: hsl(var(--foreground));
    background-color: hsl(var(--muted));
    padding: 2px 8px;
    border-radius: calc(var(--radius) - 2px);
}

.scorecard-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.scorecard-form .field {
    margin-bottom: 0;
}

.prompts-editor {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.prompts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.prompt-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4);
    background-color: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.prompt-card-top {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 4fr) auto;
    gap: var(--space-4);
    align-items: end;
}

.prompt-card-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.scorecard-form-actions {
    display: flex;
    gap: var(--space-4);
}

.scorecard-form-actions .btn {
    flex: 1;
}

/* Scorecards list */

.scorecard-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.scorecard-list .card {
    margin-top: 0;
}

.scorecard-card {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4);
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.scorecard-card:hover {
    border-color: hsl(var(--ring));
    box-shadow: var(--shadow-md);
}

/* Transparent overlay turning the whole card into a link to the edit page,
   while interactive controls (the delete button) sit above it via z-index. */
.scorecard-card-stretch {
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: var(--radius);
}

.scorecard-card-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
}

.scorecard-card-title {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
}

.scorecard-card-actions {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    border: 2px dashed hsl(var(--border));
    border-radius: var(--radius);
    text-align: center;
    color: hsl(var(--muted-foreground));
}

.empty-state p {
    margin: 0;
}

/* ==========================================================================
   8. Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    height: 40px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font: inherit;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    background-color: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
    transition:
        background-color 0.15s ease,
        color 0.15s ease,
        box-shadow 0.15s ease;
}

.btn:hover {
    text-decoration: none;
    background-color: hsl(var(--secondary) / 0.8);
}

.btn:disabled {
    pointer-events: none;
    opacity: 0.5;
}

.btn-primary {
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.btn-primary:hover {
    background-color: hsl(var(--primary) / 0.9);
}

.btn-danger {
    background-color: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}

.btn-danger:hover {
    background-color: hsl(var(--destructive) / 0.9);
}

.btn-success {
    background-color: hsl(var(--success));
    color: hsl(var(--success-foreground));
}

.btn-success:hover {
    background-color: hsl(var(--success) / 0.9);
}

.btn-ghost {
    background-color: transparent;
    color: hsl(var(--foreground));
}

.btn-ghost:hover {
    background-color: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.btn-outline {
    background-color: hsl(var(--background));
    border-color: hsl(var(--border));
    color: hsl(var(--foreground));
}

.btn-outline:hover {
    background-color: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
}

.btn-sm {
    height: 36px;
    padding: var(--space-1) var(--space-3);
    font-size: 13px;
}

/* ==========================================================================
   9. Tables
   ========================================================================== */

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    text-align: left;
    padding: var(--space-3);
    border-bottom: 1px solid hsl(var(--border));
}

.table th {
    color: hsl(var(--muted-foreground));
    font-size: 13px;
    font-weight: 600;
}

/* ==========================================================================
   10. Bars (usage / sentiment visualizations)
   ========================================================================== */

.bar-track {
    background-color: hsl(var(--muted));
    border-radius: var(--radius);
    height: 8px;
    overflow: hidden;
}

.bar-fill {
    background-color: hsl(var(--primary));
    height: 100%;
}

.bar-stacked {
    display: flex;
}

.bar-positive {
    background-color: hsl(var(--success));
}

.bar-neutral {
    background-color: hsl(var(--muted-foreground) / 0.4);
}

.bar-negative {
    background-color: hsl(var(--destructive));
}

/* ==========================================================================
   11. Badges
   ========================================================================== */

.badge {
    display: inline-block;
    padding: 2px var(--space-2);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background-color: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
}

.badge-success {
    background-color: hsl(var(--success) / 0.15);
    color: hsl(var(--success));
}

/* ==========================================================================
   12. Modals
   ========================================================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgb(0 0 0 / 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 50;
}

.modal {
    background-color: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: var(--space-6);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
}

.modal-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-6);
}

/* Slightly larger, easier-to-read text inside modals (applies to all
   dashboard modals so they stay visually consistent with each other). */
.modal .label,
.modal .field-hint,
.modal .input,
.modal .select,
.modal .textarea {
    font-size: 15px;
}

.modal .section-title {
    font-size: 17px;
}

/* ==========================================================================
   13. Toast
   ========================================================================== */

.toast {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    background-color: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: var(--space-4);
    z-index: 60;
}

/* ==========================================================================
   13b. Loading overlay
   ========================================================================== */

/* Full-viewport dimming overlay with a centered spinner, toggled by
   /js/loading-overlay.js while any user-initiated HTMX operation is in flight.
   Sits above modals (z-index 50) and toasts (z-index 60) and, because it covers
   the whole viewport, intercepts every pointer event beneath it (keyboard input
   is blocked separately in JS). */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    background-color: rgb(0 0 0 / 0.4);
    cursor: wait;
}

.loading-overlay.active {
    display: flex;
}

/* Larger, high-contrast spinner variant for the dark overlay backdrop (the
   plain .spinner is tuned for light card surfaces). Reuses spinner-rotate. */
.loading-overlay__spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgb(255 255 255 / 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

/* ==========================================================================
   14. QA analysis
   ========================================================================== */

.qa-form {
    margin-bottom: var(--space-6);
}

.qa-results {
    display: block;
}

.qa-error {
    color: hsl(var(--destructive));
    margin: var(--space-2) 0 0;
}

.qa-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    text-align: center;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid hsl(var(--border));
    border-top-color: hsl(var(--primary));
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   15. API keys
   ========================================================================== */

.pin-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.api-key-reveal {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.api-key-warning {
    color: hsl(var(--destructive));
    font-weight: 600;
    margin: 0;
}

.api-key-value {
    background-color: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    padding: var(--space-3);
    overflow-x: auto;
    margin: 0;
    font-size: 0.85rem;
}

/* ==========================================================================
   16. Dialer
   ========================================================================== */

.dialer-page {
    display: block;
}

.dialer-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.dialer-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.dialer-row .input {
    flex: 1;
}

.dialer-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.dialer-active-call {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.dialer-caller {
    font-size: 1.125rem;
    font-weight: 500;
}

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

/* ==========================================================================
   17. Theme toggle
   ========================================================================== */

.theme-toggle {
    position: relative;
}

.theme-icon-dark {
    display: none;
}

.dark .theme-icon-light {
    display: none;
}

.dark .theme-icon-dark {
    display: block;
}

.theme-toggle-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.25rem);
    z-index: 50;
    min-width: 8rem;
    padding: 0.25rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background-color: hsl(var(--popover));
    color: hsl(var(--popover-foreground));
    box-shadow: var(--shadow-md);
}

.theme-toggle-menu button {
    display: block;
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: none;
    border-radius: calc(var(--radius) - 0.25rem);
    background: none;
    color: inherit;
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}

.theme-toggle-menu button:hover,
.theme-toggle-menu button.is-active {
    background-color: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

/* ==========================================================================
   18. Helpdesk insights

   Mirrors the old React page (dashboard/src/components/helpdeskInsights/* and
   the shared BarChart component). Category-group / sentiment / urgency colors
   are applied inline (via server-rendered style attributes) using the same
   hex values as the old dashboard.
   ========================================================================== */

.hd-subline {
    margin: var(--space-1) 0 0;
}

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

.hd-filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
}

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

.hd-filter-grid .field {
    margin-bottom: 0;
}

/* Usage Metrics ----------------------------------------------------------- */

.usage-filters-title {
    font-size: 1.125rem;
    font-weight: 500;
    margin: 0 0 var(--space-4);
}

.usage-filters-actions {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.usage-charts {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.usage-chart-title {
    font-size: 1.125rem;
    font-weight: 500;
    margin: 0 0 var(--space-4);
}

/* Voice Agent Metrics pie charts ------------------------------------------ */

.va-pies {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
    align-items: stretch;
}

@media (min-width: 768px) {
    .va-pies {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
}

.va-pie-legend {
    flex-direction: column;
    align-items: flex-start;
}

.va-tool-charts {
    margin-top: var(--space-6);
}

/* Report layout ----------------------------------------------------------- */

.hd-report-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.hd-grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-6);
    align-items: stretch;
}

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

.hd-card--full {
    height: 100%;
}

.hd-card-title {
    margin: 0 0 var(--space-4);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: hsl(var(--muted-foreground));
}

.hd-card-title-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: hsl(var(--muted-foreground));
    margin-bottom: var(--space-4);
}

.hd-card-title-row .hd-card-title {
    margin: 0;
}

.hd-empty {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin: 0;
}

/* Stat cards -------------------------------------------------------------- */

.hd-stat-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
}

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

@media (min-width: 1024px) {
    .hd-stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.hd-stat-label {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin: 0 0 var(--space-2);
}

.hd-stat-value {
    font-size: 1.875rem;
    font-weight: 600;
    margin: 0 0 var(--space-2);
}

.hd-stat-subline {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin: 0;
}

.hd-stat-subline--danger {
    color: #ef4444;
}

.hd-stat-subline--warning {
    color: #f59e0b;
}

.hd-stat-subline--success {
    color: #22c55e;
}

/* Top themes by volume ---------------------------------------------------- */

.hd-theme-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.hd-theme-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.hd-theme-rank {
    width: 1rem;
    flex-shrink: 0;
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

.hd-theme-name {
    width: 11rem;
    flex-shrink: 0;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hd-theme-track {
    flex: 1;
    height: 0.5rem;
    border-radius: 9999px;
    background-color: hsl(var(--muted));
    overflow: hidden;
}

.hd-theme-fill {
    height: 100%;
    border-radius: 9999px;
}

.hd-theme-count {
    width: 3rem;
    flex-shrink: 0;
    text-align: right;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Legend (donut + sentiment) --------------------------------------------- */

.hd-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    margin-bottom: var(--space-4);
}

.hd-legend--mt {
    margin-bottom: 0;
    margin-top: var(--space-4);
}

.hd-legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.hd-legend-swatch {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 0.125rem;
}

.hd-legend-label {
    font-size: 0.75rem;
}

/* Category breakdown donut ----------------------------------------------- */

.hd-donut-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.hd-donut {
    width: 100%;
    max-width: 260px;
}

/* Sentiment by theme ------------------------------------------------------ */

.hd-sentiment-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.hd-sentiment-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.hd-sentiment-name {
    width: 10rem;
    flex-shrink: 0;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hd-sentiment-track {
    flex: 1;
    display: flex;
    height: 0.5rem;
    border-radius: 9999px;
    background-color: hsl(var(--muted));
    overflow: hidden;
}

.hd-sentiment-seg {
    height: 100%;
}

/* Bar charts (shared) ----------------------------------------------------- */

.hd-bar-group {
    position: relative;
}

.hd-bar-tooltip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: var(--space-1);
    z-index: 10;
    white-space: nowrap;
    border: 1px solid hsl(var(--border));
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    padding: var(--space-2);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: 0.75rem;
}

.hd-bar-group:hover .hd-bar-tooltip {
    display: block;
}

/* Vertical bar chart */

.hd-bar--vertical {
    display: flex;
    gap: var(--space-3);
}

.hd-bar-yaxis {
    display: flex;
    flex-direction: column-reverse;
    justify-content: space-between;
    height: 10rem;
    padding: var(--space-1) 0;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.hd-bar-plot {
    flex: 1;
    min-width: 0;
}

.hd-bar-cols {
    display: flex;
    align-items: flex-end;
    gap: var(--space-4);
    height: 10rem;
    padding-left: var(--space-2);
    padding-bottom: var(--space-1);
    border-left: 1px solid hsl(var(--border));
    border-bottom: 1px solid hsl(var(--border));
}

.hd-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    height: 100%;
}

.hd-bar-vfill {
    position: relative;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
}

.hd-bar-vfill.is-nonzero {
    min-height: 2px;
}

.hd-bar-xlabels {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-2);
}

.hd-bar-xlabel {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tall vertical bar chart (Usage Metrics) — taller plot, tighter bar gaps */
.hd-bar--tall .hd-bar-yaxis,
.hd-bar--tall .hd-bar-cols {
    height: 400px;
}

.hd-bar--tall .hd-bar-cols,
.hd-bar--tall .hd-bar-xlabels {
    gap: var(--space-1);
}

/*
 * On the tall (400px) Usage Metrics charts a single high-cost period (e.g. a
 * month of expensive model usage) can dominate the linear y axis, leaving
 * low-but-nonzero periods at well under 1px. Raise the minimum visible height
 * for nonzero bars on these charts so every period with real usage stays
 * visible and hoverable (its exact value is shown in the tooltip), without
 * changing the axis, ticks, or the relative dominance of the tall bars.
 */
.hd-bar--tall .hd-bar-vfill.is-nonzero {
    min-height: 6px;
}

/* Rotated x axis labels (Usage Metrics time series) */
.hd-bar-xlabels--rotate .hd-bar-xlabel {
    overflow: visible;
}

.hd-bar-xlabels--rotate .hd-bar-xlabel span {
    display: inline-block;
    white-space: nowrap;
    transform: rotate(-15deg);
}

/* Horizontal bar chart */

.hd-bar-hrows {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.hd-bar-hrow {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.hd-bar-hlabel {
    width: 11rem;
    flex-shrink: 0;
    text-align: right;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hd-bar-hplot {
    flex: 1;
    display: flex;
    align-items: center;
}

.hd-bar-hfill {
    position: relative;
    height: 1.5rem;
    border-radius: var(--radius);
}

.hd-bar-hfill.is-nonzero {
    min-width: 2px;
}

.hd-bar-hvalue {
    margin-left: var(--space-2);
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.hd-bar-hxaxis {
    display: flex;
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid hsl(var(--border));
}

.hd-bar-hxaxis-pad {
    width: 11rem;
    flex-shrink: 0;
}

.hd-bar-hxaxis-ticks {
    flex: 1;
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

/* Alerts ------------------------------------------------------------------ */

.hd-alert-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.hd-alert-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
}

.hd-alert-icon {
    display: inline-flex;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.hd-alert-icon .icon-sm {
    width: 1.25rem;
    height: 1.25rem;
}

.hd-alert-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.hd-alert-title {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 500;
}

.hd-alert-desc {
    margin: 0;
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

/* Recommendations --------------------------------------------------------- */

.hd-rec-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.hd-rec-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
}

.hd-rec-number {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    margin-top: 0.125rem;
    border-radius: 9999px;
    background-color: hsl(var(--muted));
    font-size: 0.75rem;
    font-weight: 500;
}

.hd-rec-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.hd-rec-title {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 500;
}

.hd-rec-desc {
    margin: 0;
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

.hd-rec-urgency {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Executive summary + quotes --------------------------------------------- */

.hd-exec-summary {
    padding: var(--space-4);
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    background-color: hsl(var(--muted) / 0.4);
}

.hd-exec-text {
    margin: 0;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.625;
    white-space: pre-wrap;
    word-break: break-word;
}

.hd-quote-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.hd-quote {
    padding: var(--space-4);
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    background-color: hsl(var(--background));
}

.hd-quote-text {
    margin: 0 0 var(--space-2);
    font-size: 0.875rem;
    font-style: italic;
}

.hd-quote-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}
