:root {
    --background: 0 0% 100%;
    --foreground: 240 10% 3.9%;
    --card: 0 0% 100%;
    --card-foreground: 240 10% 3.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 240 10% 3.9%;
    --primary: 240 5.9% 10%;
    --primary-foreground: 0 0% 98%;
    --secondary: 240 4.8% 95.9%;
    --secondary-foreground: 240 5.9% 10%;
    --muted: 240 4.8% 95.9%;
    --muted-foreground: 240 3.8% 46.1%;
    --accent: 240 4.8% 95.9%;
    --accent-foreground: 240 5.9% 10%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 5.9% 90%;
    --input: 240 5.9% 90%;
    --ring: 240 5.9% 10%;
    --radius: 0.5rem;
    --success: 142 76% 36%;
    --success-foreground: 0 0% 98%;
    --warning: 38 92% 50%;
    --warning-foreground: 0 0% 98%;
    --sidebar: 0 0% 100%;
}

.dark {
    --background: 224 71% 4%;
    --foreground: 210 20% 98%;
    --card: 224 40% 10%;
    --card-foreground: 210 20% 98%;
    --popover: 224 40% 10%;
    --popover-foreground: 210 20% 98%;
    --primary: 210 20% 98%;
    --primary-foreground: 224 71% 4%;
    --secondary: 215 28% 17%;
    --secondary-foreground: 210 20% 98%;
    --muted: 215 28% 17%;
    --muted-foreground: 217 10% 64%;
    --accent: 215 28% 17%;
    --accent-foreground: 210 20% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 210 20% 98%;
    --border: 215 20% 22%;
    --input: 215 20% 22%;
    --ring: 216 12% 84%;
    --sidebar: 224 50% 7%;
    --success: 142 71% 45%;
    --success-foreground: 210 20% 98%;
    --warning: 38 92% 50%;
    --warning-foreground: 210 20% 98%;
}

* { border-color: hsl(var(--border)); }
body { color: hsl(var(--foreground)); background-color: hsl(var(--background)); }

/* Sidebar */
.sidebar {
    width: 16rem;
    background: hsl(var(--sidebar, var(--card)));
    border-right: 1px solid hsl(var(--border));
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    transition: transform 0.2s ease;
}
.sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
    font-weight: 700;
    font-size: 1.125rem;
    color: hsl(var(--foreground));
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-brand-light { display: block; }
.sidebar-brand-dark { display: none; }
.dark .sidebar-brand-light { display: none; }
.dark .sidebar-brand-dark { display: block; }
.sidebar-nav { flex: 1; padding: 1rem 0.75rem; overflow-y: auto; }
.sidebar-section { margin-bottom: 1.5rem; }
.sidebar-section-title {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    text-decoration: none;
    transition: all 0.15s ease;
}
.sidebar-link-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
    user-select: none;
}
.sidebar-link:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}
.sidebar-link.active {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}
.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid hsl(var(--border));
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

/* Main content */
.main-content {
    margin-left: 16rem;
    min-height: 100vh;
    width: calc(100% - 16rem);
    background: hsl(40 30% 97%);
}
.dark .main-content {
    background: hsl(var(--background));
}

/* Card */
.card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    padding: 1.5rem;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.card-title { font-size: 1.125rem; font-weight: 600; }
.card-description { font-size: 0.875rem; color: hsl(var(--muted-foreground)); }

/* Button */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
    text-decoration: none;
    line-height: 1.25rem;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover { background: hsl(var(--accent)); }
.btn-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-destructive:hover { opacity: 0.9; }
.btn-outline { border-color: hsl(var(--input)); background: transparent; }
.btn-outline:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.625rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; }
.btn-icon.btn-sm { padding: 0.375rem; }

/* Input */
.input {
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--input));
    background: transparent;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
}
.input:focus {
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2);
}
.input::placeholder { color: hsl(var(--muted-foreground)); }

/* Label */
.label {
    font-size: 0.875rem;
    font-weight: 500;
    display: block;
    margin-bottom: 0.375rem;
}

/* Table */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
}
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.data-table thead { background: hsl(var(--muted)); }
table.data-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}
table.data-table td {
    padding: 0.75rem 1rem;
    border-top: 1px solid hsl(var(--border));
}
table.data-table tbody tr:hover { background: hsl(var(--muted) / 0.5); }

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 9999px;
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1rem;
}
.badge-default { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.badge-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge-success { background: hsl(var(--success)); color: hsl(var(--success-foreground)); }
.badge-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.badge-warning { background: hsl(var(--warning)); color: hsl(var(--warning-foreground)); }
.badge-outline { border: 1px solid hsl(var(--border)); background: transparent; }

/* Alert */
.alert {
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    padding: 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}
.alert-success { border-color: hsl(var(--success)); background: hsl(var(--success) / 0.1); }
.alert-destructive { border-color: hsl(var(--destructive)); background: hsl(var(--destructive) / 0.1); }
.alert-warning { border-color: hsl(var(--warning)); background: hsl(var(--warning) / 0.1); }

/* Dialog / Modal overlay */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dialog-content {
    background: hsl(var(--card));
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 32rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}
.dialog-header { margin-bottom: 1rem; }
.dialog-title { font-size: 1.125rem; font-weight: 600; }
.dialog-description { font-size: 0.875rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem; }

/* Select */
.select {
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--input));
    background: transparent;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    outline: none;
    cursor: pointer;
}
.select:focus {
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2);
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-title { font-size: 1.5rem; font-weight: 700; }

/* Stat card for dashboard */
.stat-card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    padding: 1.5rem;
}
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { font-size: 0.875rem; color: hsl(var(--muted-foreground)); }

/* Toast notification */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideIn 0.2s ease;
}
.toast-success { border-left: 3px solid hsl(var(--success)); }
.toast-error { border-left: 3px solid hsl(var(--destructive)); }

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

/* Spinner */
.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid hsl(var(--muted));
    border-top-color: hsl(var(--primary));
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* htmx loading indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

/* ===== TerHub Blue Theme ===== */
.terhub-layout {
    display: flex;
    height: 100%;
    width: 100%;
}
.terhub-sidebar {
    width: 16rem;
    background: hsl(210 80% 96%);
    border-right: 1px solid hsl(210 40% 80%);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
}
.dark .terhub-sidebar {
    background: hsl(220 60% 13%);
    border-right-color: hsl(220 50% 22%);
}
.terhub-sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid hsl(210 40% 80%);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.125rem;
    color: hsl(210 80% 40%);
}
.dark .terhub-sidebar-brand {
    border-bottom-color: hsl(220 50% 22%);
    color: hsl(210 70% 75%);
}
.terhub-sidebar-nav { flex: 1; padding: 1rem 0.75rem; overflow-y: auto; }
.terhub-sidebar-section { margin-bottom: 1.5rem; }
.terhub-sidebar-section-title {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: hsl(210 40% 55%);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.dark .terhub-sidebar-section-title { color: hsl(210 40% 55%); }
.terhub-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: hsl(210 30% 40%);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.dark .terhub-link { color: hsl(210 30% 70%); }
.terhub-link:hover {
    background: hsl(210 60% 90%);
    color: hsl(210 80% 30%);
}
.dark .terhub-link:hover {
    background: hsl(220 50% 20%);
    color: hsl(210 60% 85%);
}
.terhub-link.active {
    background: hsl(210 80% 50%);
    color: white;
}
.dark .terhub-link.active {
    background: hsl(210 70% 40%);
    color: white;
}
.terhub-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    height: calc(100vh - 0px);
}
.terhub-badge {
    background: hsl(210 80% 50%);
    color: white;
}
.terhub-badge-outline {
    border: 1px solid hsl(210 40% 70%);
    color: hsl(210 60% 40%);
    background: transparent;
}
.dark .terhub-badge-outline {
    border-color: hsl(210 30% 35%);
    color: hsl(210 40% 65%);
}
.terhub-stat {
    background: hsl(210 80% 96%);
    border: 1px solid hsl(210 40% 85%);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.dark .terhub-stat {
    background: hsl(220 55% 13%);
    border-color: hsl(220 50% 22%);
}
.terhub-stat-value { font-size: 1.75rem; font-weight: 700; color: hsl(210 80% 45%); }
.dark .terhub-stat-value { color: hsl(210 60% 65%); }
.terhub-stat-label { font-size: 0.8125rem; color: hsl(210 20% 50%); }
.terhub-card {
    background: hsl(var(--card));
    border: 1px solid hsl(210 40% 85%);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.dark .terhub-card {
    border-color: hsl(220 50% 22%);
}
.terhub-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.terhub-status-dot.connected { background: hsl(var(--success)); }
.terhub-status-dot.disconnected { background: hsl(var(--destructive)); }

/* ===== TerDrive Yellow Theme ===== */
.terdrive-layout {
    display: flex;
    height: 100%;
    width: 100%;
}
.terdrive-sidebar {
    width: 16rem;
    background: hsl(45 100% 97%);
    border-right: 1px solid hsl(45 40% 80%);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
}
.dark .terdrive-sidebar {
    background: hsl(40 60% 10%);
    border-right-color: hsl(40 50% 22%);
}
.terdrive-sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid hsl(45 40% 80%);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.125rem;
    color: hsl(45 90% 35%);
}
.dark .terdrive-sidebar-brand {
    border-bottom-color: hsl(40 50% 22%);
    color: hsl(45 70% 65%);
}
.terdrive-sidebar-nav { flex: 1; padding: 1rem 0.75rem; overflow-y: auto; }
.terdrive-sidebar-section { margin-bottom: 1.5rem; }
.terdrive-sidebar-section-title {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: hsl(45 40% 50%);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.dark .terdrive-sidebar-section-title { color: hsl(45 40% 50%); }
.terdrive-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: hsl(45 30% 35%);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.dark .terdrive-link { color: hsl(45 30% 70%); }
.terdrive-link:hover {
    background: hsl(45 60% 90%);
    color: hsl(45 80% 25%);
}
.dark .terdrive-link:hover {
    background: hsl(40 50% 18%);
    color: hsl(45 60% 78%);
}
.terdrive-link.active {
    background: hsl(45 100% 92%);
    color: hsl(40 80% 28%);
    font-weight: 600;
    box-shadow: inset 3px 0 0 hsl(43 95% 50%);
}
.dark .terdrive-link.active {
    background: hsl(43 50% 18%);
    color: hsl(45 80% 72%);
    box-shadow: inset 3px 0 0 hsl(43 80% 50%);
}
.terdrive-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    height: calc(100vh - 0px);
}
.terdrive-details {
    width: 20rem;
    background: hsl(var(--card));
    border-left: 1px solid hsl(45 40% 80%);
    flex-shrink: 0;
    overflow-y: auto;
    height: 100vh;
    position: sticky;
    top: 0;
}
.dark .terdrive-details {
    border-left-color: hsl(40 50% 22%);
}
.terdrive-badge {
    background: hsl(43 95% 50%);
    color: hsl(40 80% 14%);
}
.terdrive-badge-outline {
    border: 1px solid hsl(45 40% 70%);
    color: hsl(45 60% 35%);
    background: transparent;
}
.dark .terdrive-badge-outline {
    border-color: hsl(45 30% 35%);
    color: hsl(45 40% 65%);
}
.terdrive-stat {
    background: hsl(45 100% 97%);
    border: 1px solid hsl(45 40% 85%);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.dark .terdrive-stat {
    background: hsl(40 55% 10%);
    border-color: hsl(40 50% 22%);
}
.terdrive-stat-value { font-size: 1.75rem; font-weight: 700; color: hsl(45 90% 40%); }
.dark .terdrive-stat-value { color: hsl(45 60% 58%); }
.terdrive-stat-label { font-size: 0.8125rem; color: hsl(45 20% 45%); }
.terdrive-card {
    background: hsl(var(--card));
    border: 1px solid hsl(45 40% 85%);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.dark .terdrive-card {
    border-color: hsl(40 50% 22%);
}
