/* ==========================================================================
   LawSort Design System — app.css
   Legal Case Management SaaS Platform
   Version: 1.0.0
   ========================================================================== */

/* ==========================================================================
   1. Design Tokens (CSS Custom Properties)
   ========================================================================== */

:root {
    /* Primary */
    --navy: #1a2744;
    --navy-light: #2c3e6b;
    --navy-dark: #0f1a2e;

    /* Accent */
    --gold: #d4a843;
    --gold-light: #e8c875;
    --gold-dark: #b8912e;
    --accent: #3b82f6;
    --accent-light: #60a5fa;
    --accent-dark: #2563eb;

    /* Legal Category Colors */
    --cat-legal: #2563eb;
    --cat-medical: #059669;
    --cat-safety: #dc2626;
    --cat-contempt: #d97706;
    --cat-custody: #7c3aed;
    --cat-communication: #0891b2;
    --cat-visitation: #be185d;
    --cat-school: #4f46e5;
    --cat-alienation: #9333ea;
    --cat-other: #6b7280;

    /* Neutrals */
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface-hover: #f8fafc;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --text: #1e293b;
    --text-light: #64748b;
    --text-muted: #9ca3af;
    --text-inverse: #ffffff;

    /* Status */
    --success: #22c55e;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --error: #ef4444;
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --info: #3b82f6;
    --info-bg: #eff6ff;
    --info-border: #bfdbfe;

    /* Layout */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 60px;
    --header-height: 56px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1), 0 8px 10px rgba(0, 0, 0, 0.04);

    /* Radius */
    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition: 200ms ease;
    --transition-slow: 300ms ease;

    /* Z-index scale */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal-backdrop: 300;
    --z-modal: 400;
    --z-toast: 500;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #283548;
    --border: #334155;
    --border-light: #293548;
    --text: #f1f5f9;
    --text-light: #94a3b8;
    --text-muted: #64748b;
    --navy: #1e3a5f;
    --navy-light: #2d4a7c;
    --navy-dark: #0c1f3d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3), 0 4px 6px rgba(0, 0, 0, 0.2);
    --success-bg: #052e16;
    --success-border: #166534;
    --warning-bg: #451a03;
    --warning-border: #854d0e;
    --error-bg: #450a0a;
    --error-border: #991b1b;
    --info-bg: #172554;
    --info-border: #1e40af;
}

/* ==========================================================================
   2. Reset & Base Styles
   ========================================================================== */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
    margin-bottom: 0.5em;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-light); }

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-dark);
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5rem 0;
}

code {
    font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', Consolas, monospace;
    font-size: 0.85em;
    padding: 0.15em 0.4em;
    background: var(--border-light);
    border-radius: var(--radius-sm);
}

pre {
    padding: 1rem;
    background: var(--navy-dark);
    color: #e2e8f0;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.6;
}

pre code {
    background: none;
    padding: 0;
}

::selection {
    background: var(--accent);
    color: #fff;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================================================
   3. Layout — App Shell
   ========================================================================== */

.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
        "header header"
        "sidebar main";
    min-height: 100vh;
}

/* Header */
.header {
    grid-area: header;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--navy);
    color: var(--text-inverse);
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    box-shadow: var(--shadow);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.02em;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-brand:hover {
    color: var(--gold-light);
    text-decoration: none;
}

.header-brand-icon {
    font-size: 1.5rem;
}

.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-inverse);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

/* Sidebar */
.sidebar {
    grid-area: sidebar;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem 0;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    transition: width var(--transition-slow), transform var(--transition-slow);
}

.sidebar-section {
    padding: 0.5rem 0;
}

.sidebar-section-title {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0.5rem 1.25rem;
    margin-bottom: 0.25rem;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-item {
    display: block;
}

.sidebar-item a,
.sidebar-item button {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.25rem;
    color: var(--text-light);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition-fast);
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
    text-align: left;
    position: relative;
}

.sidebar-item a:hover,
.sidebar-item button:hover {
    color: var(--text);
    background: var(--surface-hover);
    text-decoration: none;
}

.sidebar-item.active a,
.sidebar-item.active button {
    color: var(--accent);
    background: var(--info-bg);
    font-weight: 600;
}

.sidebar-item.active a::before,
.sidebar-item.active button::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.25rem;
    bottom: 0.25rem;
    width: 3px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

.sidebar-item-icon {
    font-size: 1.125rem;
    width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-item-badge {
    margin-left: auto;
    background: var(--error);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: var(--radius-full);
    min-width: 1.25rem;
    text-align: center;
    line-height: 1.4;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 1rem;
}

/* Main Content */
.main-content {
    grid-area: main;
    padding: 1.5rem;
    min-width: 0;
    transition: margin-left var(--transition-slow);
}

.main-content.sidebar-collapsed {
    margin-left: calc(var(--sidebar-collapsed-width) - var(--sidebar-width));
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1 {
    margin-bottom: 0;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ==========================================================================
   4. Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
    font-family: inherit;
}

.btn:hover {
    background: var(--surface-hover);
    border-color: var(--text-muted);
    text-decoration: none;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled,
.btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

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

.btn-primary:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.btn-secondary {
    background: var(--navy);
    color: var(--text-inverse);
    border-color: var(--navy);
}

.btn-secondary:hover {
    background: var(--navy-light);
    border-color: var(--navy-light);
    color: var(--text-inverse);
}

.btn-danger {
    background: var(--error);
    color: #fff;
    border-color: var(--error);
}

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

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

.btn-success:hover {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

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

.btn-warning:hover {
    background: #d97706;
    border-color: #d97706;
    color: #fff;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-light);
}

.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.btn-outline-primary {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}

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

.btn-gold {
    background: var(--gold);
    color: var(--navy-dark);
    border-color: var(--gold);
    font-weight: 600;
}

.btn-gold:hover {
    background: var(--gold-dark);
    border-color: var(--gold-dark);
    color: var(--navy-dark);
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.65rem 1.5rem;
    font-size: 1rem;
}

.btn-icon {
    padding: 0.45rem;
    width: 2.25rem;
    height: 2.25rem;
}

.btn-icon.btn-sm {
    width: 1.75rem;
    height: 1.75rem;
    padding: 0.25rem;
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-group {
    display: inline-flex;
}

.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}

.btn-group .btn:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.btn-group .btn + .btn {
    margin-left: -1px;
}

/* ==========================================================================
   5. Cards
   ========================================================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
}

.card-header h2,
.card-header h3,
.card-header h4 {
    margin-bottom: 0;
    font-size: 1rem;
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface-hover);
}

.card-flush .card-body {
    padding: 0;
}

/* Stat Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.stat-card .stat-label {
    font-size: 0.8125rem;
    color: var(--text-light);
    margin-bottom: 4px;
}
.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

/* Table helpers */
.table-wrap {
    overflow-x: auto;
}
.table-wrap table,
.card > .table-wrap > table,
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
table th {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table tbody tr:last-child td {
    border-bottom: none;
}
table tbody tr:hover td {
    background: var(--bg);
}

/* Page header subtitle */
.page-subtitle {
    color: var(--text-light);
    font-size: 0.9375rem;
    margin-top: 4px;
}

/* ==========================================================================
   6. Badges
   ========================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.5;
    border-radius: var(--radius-full);
    white-space: nowrap;
    background: var(--border-light);
    color: var(--text-light);
}

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

.badge-success {
    background: var(--success-bg);
    color: #166534;
    border: 1px solid var(--success-border);
}

.badge-warning {
    background: var(--warning-bg);
    color: #92400e;
    border: 1px solid var(--warning-border);
}

.badge-error,
.badge-danger {
    background: var(--error-bg);
    color: #991b1b;
    border: 1px solid var(--error-border);
}

.badge-info {
    background: var(--info-bg);
    color: #1e40af;
    border: 1px solid var(--info-border);
}

/* Legal Category Badges */
.badge-legal       { background: #dbeafe; color: #1e40af; }
.badge-medical     { background: #d1fae5; color: #065f46; }
.badge-safety      { background: #fee2e2; color: #991b1b; }
.badge-contempt    { background: #fef3c7; color: #92400e; }
.badge-custody     { background: #ede9fe; color: #5b21b6; }
.badge-communication { background: #cffafe; color: #155e75; }
.badge-visitation  { background: #fce7f3; color: #9d174d; }
.badge-school      { background: #e0e7ff; color: #3730a3; }
.badge-alienation  { background: #f3e8ff; color: #6b21a8; }
.badge-other       { background: #f3f4f6; color: #4b5563; }

/* Dark theme badge overrides */
[data-theme="dark"] .badge-success { color: #86efac; }
[data-theme="dark"] .badge-warning { color: #fcd34d; }
[data-theme="dark"] .badge-error,
[data-theme="dark"] .badge-danger  { color: #fca5a5; }
[data-theme="dark"] .badge-info    { color: #93c5fd; }
[data-theme="dark"] .badge-legal       { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-medical     { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-safety      { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .badge-contempt    { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .badge-custody     { background: #4c1d95; color: #c4b5fd; }
[data-theme="dark"] .badge-communication { background: #164e63; color: #67e8f9; }
[data-theme="dark"] .badge-visitation  { background: #831843; color: #f9a8d4; }
[data-theme="dark"] .badge-school      { background: #312e81; color: #a5b4fc; }
[data-theme="dark"] .badge-alienation  { background: #581c87; color: #d8b4fe; }
[data-theme="dark"] .badge-other       { background: #374151; color: #d1d5db; }

.badge-lg {
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
}

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

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.35rem;
}

.form-label-optional {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

.form-input,
.form-select,
.form-textarea {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    appearance: none;
}

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

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
    background: var(--border-light);
    color: var(--text-muted);
    cursor: not-allowed;
}

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8.825a.5.5 0 0 1-.354-.146l-4-4a.5.5 0 1 1 .708-.708L6 7.617l3.646-3.646a.5.5 0 0 1 .708.708l-4 4A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px;
    padding-right: 2rem;
}

.form-textarea {
    resize: vertical;
    min-height: 5rem;
}

.form-checkbox,
.form-radio {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.form-checkbox input[type="checkbox"],
.form-radio input[type="radio"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.form-error {
    color: var(--error);
    font-size: 0.8125rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid {
    border-color: var(--error);
}

.form-input.is-invalid:focus,
.form-select.is-invalid:focus,
.form-textarea.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.form-help {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group .form-input {
    border-radius: 0;
}

.input-group .form-input:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}

.input-group .form-input:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.input-group .btn {
    border-radius: 0;
}

.input-group .btn:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--text-light);
    background: var(--border-light);
    border: 1px solid var(--border);
}

/* ==========================================================================
   8. Tables
   ========================================================================== */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th,
.table td {
    padding: 0.65rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table th {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-light);
    background: var(--surface-hover);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table-striped tbody tr:nth-child(even) {
    background: var(--surface-hover);
}

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

.th-sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.5rem !important;
}

.th-sortable::after {
    content: '\2195';
    position: absolute;
    right: 0.5rem;
    opacity: 0.3;
    font-size: 0.75rem;
}

.th-sortable.asc::after {
    content: '\2191';
    opacity: 1;
    color: var(--accent);
}

.th-sortable.desc::after {
    content: '\2193';
    opacity: 1;
    color: var(--accent);
}

.table-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   9. Alerts
   ========================================================================== */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    position: relative;
}

.alert-icon {
    font-size: 1.125rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
}

.alert-content {
    flex: 1;
    min-width: 0;
}

.alert-dismiss {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.125rem;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}

.alert-dismiss:hover {
    opacity: 1;
}

.alert-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: #166534;
}

.alert-error {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: #991b1b;
}

.alert-warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: #92400e;
}

.alert-info {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: #1e40af;
}

[data-theme="dark"] .alert-success { color: #86efac; }
[data-theme="dark"] .alert-error   { color: #fca5a5; }
[data-theme="dark"] .alert-warning { color: #fcd34d; }
[data-theme="dark"] .alert-info    { color: #93c5fd; }

/* ==========================================================================
   10. Modals
   ========================================================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-backdrop);
    padding: 1rem;
    animation: fadeIn var(--transition-fast);
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    animation: slideUp var(--transition);
    z-index: var(--z-modal);
}

.modal-sm { max-width: 380px; }
.modal-md { max-width: 500px; }
.modal-lg { max-width: 700px; }
.modal-xl { max-width: 900px; }
.modal-full { max-width: calc(100vw - 2rem); }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-header h3,
.modal-header h4 {
    margin-bottom: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==========================================================================
   11. Stat Cards (Dashboard)
   ========================================================================== */

.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-fast);
}

.stat-card:hover {
    box-shadow: var(--shadow);
}

.stat-card-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.35rem;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-card-change {
    font-size: 0.8125rem;
    margin-top: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stat-card-change.positive { color: var(--success); }
.stat-card-change.negative { color: var(--error); }

.stat-card-icon {
    float: right;
    font-size: 1.75rem;
    opacity: 0.3;
    margin-top: -0.25rem;
}

/* ==========================================================================
   12. Empty State
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.empty-state-text {
    font-size: 0.875rem;
    max-width: 360px;
    margin: 0 auto 1.25rem;
    line-height: 1.5;
}

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

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    max-width: 420px;
    font-size: 0.875rem;
    animation: toastIn var(--transition) ease-out;
    pointer-events: auto;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error   { border-left: 4px solid var(--error); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info    { border-left: 4px solid var(--info); }

.toast-dismiss {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    margin-left: auto;
    font-size: 1rem;
    flex-shrink: 0;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

/* ==========================================================================
   14. Dropdowns
   ========================================================================== */

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0.35rem 0;
    z-index: var(--z-dropdown);
    animation: fadeIn var(--transition-fast);
    margin-top: 0.25rem;
}

.dropdown-menu-left {
    right: auto;
    left: 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.9rem;
    font-size: 0.875rem;
    color: var(--text);
    text-decoration: none;
    transition: background var(--transition-fast);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.dropdown-item:hover {
    background: var(--surface-hover);
    text-decoration: none;
}

.dropdown-item-danger {
    color: var(--error);
}

.dropdown-item-danger:hover {
    background: var(--error-bg);
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 0.35rem 0;
}

.dropdown-header {
    padding: 0.35rem 0.9rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ==========================================================================
   15. Breadcrumbs
   ========================================================================== */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
    font-size: 0.8125rem;
}

.breadcrumb li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
}

.breadcrumb li + li::before {
    content: '/';
    color: var(--text-muted);
    opacity: 0.5;
}

.breadcrumb a {
    color: var(--text-light);
}

.breadcrumb a:hover {
    color: var(--accent);
}

.breadcrumb li:last-child {
    color: var(--text);
    font-weight: 500;
}

/* ==========================================================================
   16. Pagination
   ========================================================================== */

.pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    list-style: none;
    padding: 0;
    margin: 1.5rem 0 0;
    justify-content: center;
}

.pagination li a,
.pagination li span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    transition: all var(--transition-fast);
}

.pagination li a:hover {
    background: var(--surface-hover);
    border-color: var(--text-muted);
    color: var(--text);
    text-decoration: none;
}

.pagination li.active span {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.pagination li.disabled span {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-info {
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.5rem;
}

/* ==========================================================================
   17. Tabs
   ========================================================================== */

.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.25rem;
    gap: 0;
    overflow-x: auto;
}

.tab-item {
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-light);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.tab-item:hover {
    color: var(--text);
    text-decoration: none;
}

.tab-item.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Tab-btn alias (used in case detail view) */
.tab-btn {
    padding: 0.75rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-light);
    text-decoration: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
    background: none;
    font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

/* ==========================================================================
   17b. Case Detail Components
   ========================================================================== */

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-light);
    font-size: 0.875rem;
    text-decoration: none;
    margin-bottom: 16px;
    transition: color 0.15s;
}
.back-link:hover { color: var(--accent); }

.card-lg { padding: 24px; }

/* Detail Grid — metadata display */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}
.detail-item {}
.detail-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}
.detail-value {
    font-size: 0.9375rem;
    color: var(--text);
    line-height: 1.5;
}

/* Team Members */
.team-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.team-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px 6px 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.875rem;
}
.team-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

/* Activity Feed */
.activity-feed {
    list-style: none;
    padding: 0;
    margin: 0;
}
.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: 5px;
}
.activity-summary {
    font-size: 0.9375rem;
    color: var(--text);
}
.activity-time {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Kanban Board */
.kanban {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 8px;
}
.kanban-col {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 12px;
    min-height: 120px;
}
.kanban-col-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}
.kanban-col-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text);
}
.kanban-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
    transition: box-shadow 0.15s;
    cursor: default;
}
.kanban-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--accent);
}
.kanban-card:last-child { margin-bottom: 0; }
.kanban-card-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
}
.kanban-card-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Priority badges */
.badge-urgent { background: #dc2626; color: #fff; }
.badge-high { background: #f59e0b; color: #fff; }
.badge-normal { background: #6b7280; color: #fff; }
.badge-low { background: #d1d5db; color: #374151; }

/* Case type badges */
.badge-family { background: #7c3aed; color: #fff; }
.badge-civil { background: #2563eb; color: #fff; }
.badge-criminal { background: #dc2626; color: #fff; }
.badge-corporate { background: #0891b2; color: #fff; }
.badge-immigration { background: #059669; color: #fff; }
.badge-probate { background: #d97706; color: #fff; }
.badge-custody { background: #9333ea; color: #fff; }
.badge-other { background: #6b7280; color: #fff; }

/* Case status badges */
.badge-open { background: #22c55e; color: #fff; }
.badge-closed { background: #6b7280; color: #fff; }
.badge-archived { background: #9ca3af; color: #fff; }

/* Invoice status badges */
.badge-draft { background: #d1d5db; color: #374151; }
.badge-sent { background: #3b82f6; color: #fff; }
.badge-paid { background: #22c55e; color: #fff; }
.badge-overdue { background: #dc2626; color: #fff; }
.badge-cancelled { background: #9ca3af; color: #fff; }

/* Tab panel padding */
.tabs + [x-show],
.tabs ~ [x-show] {
    padding: 20px;
}

/* Spinner */
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive kanban */
@media (max-width: 768px) {
    .kanban {
        grid-template-columns: 1fr;
    }
    .detail-grid {
        grid-template-columns: 1fr 1fr;
    }
}
@media (max-width: 480px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   18. Search Input
   ========================================================================== */

.search-input {
    position: relative;
}

.search-input input {
    padding-left: 2.25rem;
}

.search-input::before {
    content: '\1F50D';
    position: absolute;
    left: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.875rem;
    opacity: 0.4;
    pointer-events: none;
    z-index: 1;
}

.search-input-kbd {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6875rem;
    color: var(--text-muted);
    background: var(--border-light);
    padding: 0.1rem 0.35rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    pointer-events: none;
}

.global-search {
    background: var(--navy-light);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius);
    color: #fff;
    padding: 0.4rem 0.75rem 0.4rem 2rem;
    font-size: 0.8125rem;
    width: 240px;
    transition: all var(--transition);
}

.global-search::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.global-search:focus {
    width: 320px;
    background: var(--navy-dark);
    border-color: var(--gold);
    outline: none;
}

/* ==========================================================================
   19. Avatars
   ========================================================================== */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #fff;
    flex-shrink: 0;
    line-height: 1;
}

.avatar-sm { width: 1.5rem; height: 1.5rem; font-size: 0.625rem; }
.avatar-lg { width: 2.75rem; height: 2.75rem; font-size: 1rem; }
.avatar-xl { width: 3.5rem; height: 3.5rem; font-size: 1.25rem; }

.avatar-blue    { background: var(--accent); }
.avatar-green   { background: var(--success); }
.avatar-purple  { background: var(--cat-custody); }
.avatar-orange  { background: var(--cat-contempt); }
.avatar-red     { background: var(--error); }
.avatar-navy    { background: var(--navy); }
.avatar-gold    { background: var(--gold); color: var(--navy-dark); }

.avatar-group {
    display: flex;
}

.avatar-group .avatar {
    margin-left: -0.5rem;
    border: 2px solid var(--surface);
}

.avatar-group .avatar:first-child {
    margin-left: 0;
}

/* ==========================================================================
   20. Timeline Events
   ========================================================================== */

.timeline {
    position: relative;
    padding-left: 1.5rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-event {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition-fast);
}

.timeline-event:hover {
    box-shadow: var(--shadow-sm);
}

.timeline-event::before {
    content: '';
    position: absolute;
    left: -1.75rem;
    top: 1rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border);
}

/* Category-colored timeline events */
.timeline-event.cat-legal       { border-left-color: var(--cat-legal); }
.timeline-event.cat-medical     { border-left-color: var(--cat-medical); }
.timeline-event.cat-safety      { border-left-color: var(--cat-safety); }
.timeline-event.cat-contempt    { border-left-color: var(--cat-contempt); }
.timeline-event.cat-custody     { border-left-color: var(--cat-custody); }
.timeline-event.cat-communication { border-left-color: var(--cat-communication); }
.timeline-event.cat-visitation  { border-left-color: var(--cat-visitation); }
.timeline-event.cat-school      { border-left-color: var(--cat-school); }
.timeline-event.cat-alienation  { border-left-color: var(--cat-alienation); }
.timeline-event.cat-other       { border-left-color: var(--cat-other); }

.timeline-event.cat-legal::before       { border-color: var(--cat-legal); }
.timeline-event.cat-medical::before     { border-color: var(--cat-medical); }
.timeline-event.cat-safety::before      { border-color: var(--cat-safety); }
.timeline-event.cat-contempt::before    { border-color: var(--cat-contempt); }
.timeline-event.cat-custody::before     { border-color: var(--cat-custody); }
.timeline-event.cat-communication::before { border-color: var(--cat-communication); }
.timeline-event.cat-visitation::before  { border-color: var(--cat-visitation); }
.timeline-event.cat-school::before      { border-color: var(--cat-school); }
.timeline-event.cat-alienation::before  { border-color: var(--cat-alienation); }
.timeline-event.cat-other::before       { border-color: var(--cat-other); }

.timeline-event-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
    gap: 0.5rem;
}

.timeline-event-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text);
}

.timeline-event-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.timeline-event-body {
    font-size: 0.875rem;
    color: var(--text-light);
    line-height: 1.5;
}

.timeline-event-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ==========================================================================
   21. Category Dot
   ========================================================================== */

.category-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.category-dot-sm { width: 8px; height: 8px; }
.category-dot-lg { width: 12px; height: 12px; }

.category-dot-legal       { background: var(--cat-legal); }
.category-dot-medical     { background: var(--cat-medical); }
.category-dot-safety      { background: var(--cat-safety); }
.category-dot-contempt    { background: var(--cat-contempt); }
.category-dot-custody     { background: var(--cat-custody); }
.category-dot-communication { background: var(--cat-communication); }
.category-dot-visitation  { background: var(--cat-visitation); }
.category-dot-school      { background: var(--cat-school); }
.category-dot-alienation  { background: var(--cat-alienation); }
.category-dot-other       { background: var(--cat-other); }

/* ==========================================================================
   22. Exhibit Badge
   ========================================================================== */

.exhibit-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--gold);
    color: var(--navy-dark);
    border-radius: var(--radius-sm);
    letter-spacing: 0.02em;
}

.exhibit-badge-sm {
    padding: 0.1rem 0.4rem;
    font-size: 0.6875rem;
}

.exhibit-badge-lg {
    padding: 0.3rem 0.85rem;
    font-size: 0.875rem;
}

/* ==========================================================================
   23. Priority Badge
   ========================================================================== */

.priority-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
}

.priority-low {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.priority-normal {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.priority-high {
    background: #fff7ed;
    color: #9a3412;
    border: 1px solid #fed7aa;
}

.priority-urgent {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    animation: urgentPulse 2s ease-in-out infinite;
}

@keyframes urgentPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

[data-theme="dark"] .priority-low    { background: #052e16; color: #86efac; border-color: #166534; }
[data-theme="dark"] .priority-normal { background: #172554; color: #93c5fd; border-color: #1e40af; }
[data-theme="dark"] .priority-high   { background: #431407; color: #fdba74; border-color: #9a3412; }
[data-theme="dark"] .priority-urgent { background: #450a0a; color: #fca5a5; border-color: #991b1b; }

/* ==========================================================================
   24. Status Badges
   ========================================================================== */

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Case Statuses */
.status-active    { background: #dbeafe; color: #1e40af; }
.status-active::before { background: #3b82f6; }

.status-pending   { background: #fef3c7; color: #92400e; }
.status-pending::before { background: #f59e0b; }

.status-closed    { background: #f3f4f6; color: #4b5563; }
.status-closed::before { background: #9ca3af; }

.status-settled   { background: #d1fae5; color: #065f46; }
.status-settled::before { background: #10b981; }

/* Task Statuses */
.status-todo      { background: #f3f4f6; color: #4b5563; }
.status-todo::before { background: #9ca3af; }

.status-in-progress { background: #dbeafe; color: #1e40af; }
.status-in-progress::before { background: #3b82f6; }

.status-completed { background: #d1fae5; color: #065f46; }
.status-completed::before { background: #10b981; }

.status-overdue   { background: #fef2f2; color: #991b1b; }
.status-overdue::before { background: #ef4444; }

/* Invoice Statuses */
.status-draft     { background: #f3f4f6; color: #4b5563; }
.status-draft::before { background: #9ca3af; }

.status-sent      { background: #dbeafe; color: #1e40af; }
.status-sent::before { background: #3b82f6; }

.status-paid      { background: #d1fae5; color: #065f46; }
.status-paid::before { background: #10b981; }

[data-theme="dark"] .status-active      { background: #172554; color: #93c5fd; }
[data-theme="dark"] .status-pending     { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .status-closed      { background: #374151; color: #d1d5db; }
[data-theme="dark"] .status-settled     { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .status-todo        { background: #374151; color: #d1d5db; }
[data-theme="dark"] .status-in-progress { background: #172554; color: #93c5fd; }
[data-theme="dark"] .status-completed   { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .status-overdue     { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .status-draft       { background: #374151; color: #d1d5db; }
[data-theme="dark"] .status-sent        { background: #172554; color: #93c5fd; }
[data-theme="dark"] .status-paid        { background: #064e3b; color: #6ee7b7; }

/* ==========================================================================
   25. Notification Bell
   ========================================================================== */

.notification-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    cursor: pointer;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.125rem;
    transition: color var(--transition-fast);
    border-radius: var(--radius);
}

.notification-bell:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.notification-count {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 1rem;
    height: 1rem;
    background: var(--error);
    color: #fff;
    font-size: 0.625rem;
    font-weight: 700;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.25rem;
    line-height: 1;
}

/* ==========================================================================
   26. User Menu
   ========================================================================== */

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    transition: background var(--transition-fast);
}

.user-menu:hover {
    background: rgba(255, 255, 255, 0.1);
}

.user-menu-name {
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.9);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-caret {
    font-size: 0.625rem;
    color: rgba(255, 255, 255, 0.5);
}

/* ==========================================================================
   27. Case Selector
   ========================================================================== */

.case-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.65rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    max-width: 200px;
}

.case-selector:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
}

.case-selector-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   28. Loading & Spinners
   ========================================================================== */

.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-sm { width: 0.875rem; height: 0.875rem; border-width: 1.5px; }
.spinner-lg { width: 2rem; height: 2rem; border-width: 3px; }

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

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
}

[data-theme="dark"] .loading-overlay {
    background: rgba(15, 23, 42, 0.7);
}

/* HTMX loading indicator */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-flex;
}

.htmx-request.htmx-indicator {
    display: inline-flex;
}

/* Skeleton loader */
.skeleton {
    background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

.skeleton-text {
    height: 0.875rem;
    margin-bottom: 0.5rem;
    width: 100%;
}

.skeleton-text:last-child {
    width: 70%;
}

.skeleton-heading {
    height: 1.5rem;
    width: 40%;
    margin-bottom: 1rem;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================================================
   29. Utility Classes
   ========================================================================== */

/* Flexbox */
.flex             { display: flex; }
.inline-flex      { display: inline-flex; }
.flex-col         { flex-direction: column; }
.flex-wrap        { flex-wrap: wrap; }
.items-center     { align-items: center; }
.items-start      { align-items: flex-start; }
.items-end        { align-items: flex-end; }
.justify-between  { justify-content: space-between; }
.justify-center   { justify-content: center; }
.justify-end      { justify-content: flex-end; }
.flex-1           { flex: 1; }
.flex-shrink-0    { flex-shrink: 0; }

/* Grid */
.grid             { display: grid; }
.grid-cols-2      { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3      { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4      { grid-template-columns: repeat(4, 1fr); }

/* Gap */
.gap-1  { gap: 0.25rem; }
.gap-2  { gap: 0.5rem; }
.gap-3  { gap: 0.75rem; }
.gap-4  { gap: 1rem; }
.gap-6  { gap: 1.5rem; }
.gap-8  { gap: 2rem; }

/* Margin */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }

.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Padding */
.p-0  { padding: 0; }
.p-1  { padding: 0.25rem; }
.p-2  { padding: 0.5rem; }
.p-3  { padding: 0.75rem; }
.p-4  { padding: 1rem; }
.p-6  { padding: 1.5rem; }
.p-8  { padding: 2rem; }

.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }

/* Typography */
.text-xs    { font-size: 0.75rem; }
.text-sm    { font-size: 0.8125rem; }
.text-base  { font-size: 0.9375rem; }
.text-lg    { font-size: 1.125rem; }
.text-xl    { font-size: 1.25rem; }
.text-2xl   { font-size: 1.5rem; }

.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold   { font-weight: 700; }

.text-muted  { color: var(--text-muted); }
.text-light  { color: var(--text-light); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error  { color: var(--error); }
.text-gold   { color: var(--gold); }

.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-left   { text-align: left; }

.uppercase   { text-transform: uppercase; }
.capitalize  { text-transform: capitalize; }
.tracking-wide { letter-spacing: 0.05em; }

/* Layout Utilities */
.hidden       { display: none !important; }
.block        { display: block; }
.inline-block { display: inline-block; }
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.w-full       { width: 100%; }
.h-full       { height: 100%; }
.max-w-sm     { max-width: 24rem; }
.max-w-md     { max-width: 28rem; }
.max-w-lg     { max-width: 32rem; }
.max-w-xl     { max-width: 36rem; }
.max-w-2xl    { max-width: 42rem; }
.max-w-4xl    { max-width: 56rem; }
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.sticky   { position: sticky; }

/* Borders */
.border      { border: 1px solid var(--border); }
.border-t    { border-top: 1px solid var(--border); }
.border-b    { border-bottom: 1px solid var(--border); }
.rounded     { border-radius: var(--radius); }
.rounded-lg  { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

/* Shadows */
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow    { box-shadow: var(--shadow); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* Visibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.no-print { /* Used in print media query */ }

/* Cursor */
.cursor-pointer { cursor: pointer; }

/* ==========================================================================
   30. Responsive
   ========================================================================== */

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

    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main";
    }

    .hamburger {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        width: var(--sidebar-width);
        height: calc(100vh - var(--header-height));
        transform: translateX(-100%);
        z-index: var(--z-modal-backdrop);
        box-shadow: var(--shadow-xl);
        transition: transform var(--transition-slow);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        top: var(--header-height);
        background: rgba(0, 0, 0, 0.5);
        z-index: calc(var(--z-modal-backdrop) - 1);
    }

    .main-content {
        padding: 1rem;
    }

    .main-content.sidebar-collapsed {
        margin-left: 0;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

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

    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }

    .global-search {
        display: none;
    }

    .user-menu-name {
        display: none;
    }

    .modal {
        margin: 0.5rem;
        max-height: calc(100vh - 1rem);
    }

    .table-wrapper {
        margin-left: -1rem;
        margin-right: -1rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .hide-mobile {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0 0.75rem;
    }

    .main-content {
        padding: 0.75rem;
    }

    .card-body {
        padding: 0.85rem;
    }

    .card-header {
        padding: 0.75rem 0.85rem;
    }

    .btn-group {
        flex-direction: column;
    }

    .btn-group .btn {
        border-radius: var(--radius);
    }

    .btn-group .btn + .btn {
        margin-left: 0;
        margin-top: -1px;
    }
}

@media (min-width: 769px) {
    .show-mobile {
        display: none !important;
    }
}

/* ==========================================================================
   31. Print Styles
   ========================================================================== */

@media print {
    .sidebar,
    .header,
    .no-print,
    .btn,
    .toast-container,
    .modal-overlay,
    .hamburger,
    .notification-bell,
    .user-menu,
    .case-selector,
    .global-search,
    .search-input,
    .pagination,
    .sidebar-backdrop {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
        font-size: 11pt;
    }

    .app-layout {
        display: block;
    }

    .main-content {
        margin: 0;
        padding: 0;
    }

    .card {
        border: 1px solid #000;
        box-shadow: none;
        break-inside: avoid;
    }

    .card-header {
        background: #f5f5f5;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    a {
        color: #000;
        text-decoration: underline;
    }

    .badge,
    .status-badge,
    .priority-badge,
    .exhibit-badge {
        border: 1px solid #999;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .timeline-event {
        border-left-width: 3px;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        break-inside: avoid;
    }

    h1, h2, h3, h4 {
        break-after: avoid;
    }

    table {
        break-inside: avoid;
    }

    .table th {
        background: #f0f0f0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
