/* ==========================================================================
   CANVAS DESIGN SYSTEM v2.0
   Pure Monochrome Minimalism - Production Ready
   SINGLE SOURCE OF TRUTH - Do not override these variables elsewhere
   ========================================================================== */

/* ==========================================================================
   CSS VARIABLES - LIGHT MODE (Default)
   ========================================================================== */

:root {
    /* Primary Colors - Pure Monochrome */
    --primary: #000000;
    --primary-hover: #171717;
    --primary-light: rgba(0, 0, 0, 0.05);

    /* Background Colors */
    --bg-primary: #FFFFFF;
    --bg-secondary: #FAFAFA;
    --bg-tertiary: #F5F5F5;
    --bg-card: #FFFFFF;
    --bg-hover: #F5F5F5;
    --bg-active: #EBEBEB;

    /* Text Colors */
    --text-primary: #0A0A0A;
    --text-secondary: #525252;
    --text-tertiary: #737373;
    --text-muted: #A3A3A3;

    /* Border Colors */
    --border: #E5E5E5;
    --border-strong: #D4D4D4;
    --border-focus: #000000;

    /* Semantic Colors - Status Only */
    --success: #22C55E;
    --success-bg: #F0FDF4;
    --warning: #EAB308;
    --warning-bg: #FEFCE8;
    --error: #EF4444;
    --error-bg: #FEF2F2;
    --info: #3B82F6;
    --info-bg: #EFF6FF;

    /* Typography */
    --font-heading: 'Instrument Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

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

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

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

    /* Sidebar */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 48px;
    --sidebar-current-width: var(--sidebar-width);
}

/* ==========================================================================
   CSS VARIABLES - DARK MODE
   ========================================================================== */

[data-theme="dark"],
.theme-dark,
.dark,
html.dark,
html[data-theme="dark"] {
    /* Primary Colors - Inverted Monochrome */
    --primary: #FFFFFF;
    --primary-hover: #E5E5E5;
    --primary-light: rgba(255, 255, 255, 0.1);

    /* Background Colors - TRUE BLACK (consistent everywhere) */
    --bg-primary: #0A0A0A;
    --bg-secondary: #141414;
    --bg-tertiary: #1F1F1F;
    --bg-card: #141414;
    --bg-hover: #1F1F1F;
    --bg-active: #292929;

    /* Text Colors */
    --text-primary: #FAFAFA;
    --text-secondary: #A3A3A3;
    --text-tertiary: #737373;
    --text-muted: #525252;

    /* Border Colors */
    --border: #292929;
    --border-strong: #404040;
    --border-focus: #FFFFFF;

    /* Semantic Colors - Adjusted for dark mode */
    --success-bg: #14532D;
    --warning-bg: #422006;
    --error-bg: #450A0A;
    --info-bg: #1E3A5F;

    /* Shadows - Dark mode adjusted */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   BASE STYLES - Browser Compatibility & Reset
   ========================================================================== */

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

html {
    /* Prevent font-size inflation on mobile */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Smooth scrolling */
    scroll-behavior: smooth;
    /* Better font rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Base font size for rem calculations */
    font-size: 16px;
    /* Prevent horizontal overflow */
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color var(--transition-base), color var(--transition-base);
    /* Prevent horizontal overflow */
    overflow-x: hidden;
    /* Minimum readable size */
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
}

body.app-body {
    background-color: var(--bg-primary);
}

/* Ensure images scale properly */
img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Remove default button styling inconsistencies */
button, input, textarea, select {
    font: inherit;
    color: inherit;
}

/* Ensure links inherit color properly */
a {
    color: inherit;
    text-decoration: none;
}

/* Better table defaults */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* ==========================================================================
   LAYOUT
   ========================================================================== */

.page-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.page-header-content {
    flex: 1;
}

.page-header-actions {
    display: flex;
    gap: 12px;
}

.page-title {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
}

.main-content {
    flex: 1;
    padding: 48px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* ==========================================================================
   THEME TOGGLE
   ========================================================================== */

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-toggle-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.theme-toggle-btn {
    width: 48px;
    height: 24px;
    border-radius: 12px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-strong);
    cursor: pointer;
    position: relative;
    transition: background-color var(--transition-base);
}

.theme-toggle-btn::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: var(--text-primary);
    top: 2px;
    left: 2px;
    transition: transform var(--transition-base);
}

[data-theme="dark"] .theme-toggle-btn::after {
    transform: translateX(24px);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-body);
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    text-decoration: none;
}

/* Button Sizes */
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-md {
    padding: 10px 16px;
    font-size: 14px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
}

/* Button Variants */
.btn-primary {
    background-color: var(--accent);
    color: #FFFFFF;
    border-color: var(--accent);
}

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

/* Black variant for contrast */
.btn-black {
    background-color: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.btn-black:hover {
    opacity: 0.85;
}

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-secondary:hover {
    background-color: var(--bg-tertiary);
}

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

.btn-ghost:hover {
    background-color: var(--bg-secondary);
}

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

.btn-danger:hover {
    opacity: 0.85;
}

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

.btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* ==========================================================================
   FORM INPUTS
   ========================================================================== */

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--bg-tertiary);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

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

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

/* Checkbox */
.form-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.form-checkbox input {
    width: 18px;
    height: 18px;
    accent-color: var(--text-primary);
    cursor: pointer;
}

.form-checkbox-label {
    font-size: 14px;
    color: var(--text-primary);
}

/* Radio */
.form-radio {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.form-radio input {
    width: 18px;
    height: 18px;
    accent-color: var(--text-primary);
    cursor: pointer;
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-switch-input {
    position: relative;
    width: 44px;
    height: 24px;
    appearance: none;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.toggle-switch-input::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: var(--text-tertiary);
    top: 2px;
    left: 2px;
    transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.toggle-switch-input:checked {
    background-color: var(--text-primary);
    border-color: var(--text-primary);
}

.toggle-switch-input:checked::after {
    transform: translateX(20px);
    background-color: var(--bg-primary);
}

/* ==========================================================================
   CARDS
   ========================================================================== */

.card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base), transform var(--transition-base);
}

.card-image {
    width: 100%;
    height: 160px;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-image svg {
    width: 48px;
    height: 48px;
    stroke: var(--text-tertiary);
    fill: none;
    stroke-width: 1;
}

.card-body {
    padding: 20px;
}

.card-title {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.card-text {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-interactive:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-interactive {
    cursor: pointer;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

/* ==========================================================================
   TABLES
   ========================================================================== */

.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--bg-primary);
    box-shadow: var(--shadow-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table th.sortable {
    cursor: pointer;
    user-select: none;
}

.table th.sortable:hover {
    background-color: var(--bg-tertiary);
}

.table th svg {
    width: 14px;
    height: 14px;
    stroke: var(--text-tertiary);
    fill: none;
    stroke-width: 2;
    vertical-align: middle;
    margin-left: 4px;
}

.table td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 14px;
}

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

.table tr:hover td {
    background-color: var(--bg-secondary);
}

.table-actions {
    display: flex;
    gap: 8px;
}

.table-action-btn {
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid var(--border-strong);
    background-color: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.table-action-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ==========================================================================
   MODALS
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background-color: var(--bg-primary);
    border-radius: 12px;
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform var(--transition-base);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

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

.modal-title {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background-color: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast);
}

.modal-close:hover {
    background-color: var(--bg-secondary);
}

.modal-close svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-secondary);
    fill: none;
    stroke-width: 2;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ==========================================================================
   BADGES / TAGS
   ========================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 9999px;
    white-space: nowrap;
}

.badge-default {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.badge-active {
    background-color: var(--success-bg);
    color: var(--success);
}

.badge-pending {
    background-color: var(--warning-bg);
    color: var(--warning);
}

.badge-archived {
    background-color: var(--bg-tertiary);
    color: var(--text-tertiary);
}

.badge-admin {
    background-color: var(--text-primary);
    color: var(--bg-primary);
}

.badge-user {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}

.badge-error {
    background-color: var(--error-bg);
    color: var(--error);
}

/* Tags (removable) */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 10px;
    font-size: 12px;
    font-weight: 500;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.tag-remove {
    width: 16px;
    height: 16px;
    border: none;
    background-color: transparent;
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tag-remove:hover {
    background-color: var(--bg-tertiary);
}

.tag-remove svg {
    width: 12px;
    height: 12px;
    stroke: var(--text-tertiary);
    fill: none;
    stroke-width: 2;
}

/* ==========================================================================
   ALERTS
   ========================================================================== */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border-radius: 8px;
    font-size: 14px;
}

.alert svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 600;
    margin-bottom: 4px;
}

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

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

.alert-warning {
    background-color: var(--warning-bg);
    color: var(--warning);
    border: 1px solid var(--warning);
}

.alert-error {
    background-color: var(--error-bg);
    color: var(--error);
    border: 1px solid var(--error);
}

/* ==========================================================================
   NAVIGATION
   ========================================================================== */

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: -1px;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--text-primary);
}

/* Breadcrumbs */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.breadcrumb-item {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.breadcrumb-item:hover {
    color: var(--text-primary);
}

.breadcrumb-item.active {
    color: var(--text-primary);
    font-weight: 500;
}

.breadcrumb-separator {
    color: var(--text-tertiary);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pagination-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-body);
    color: var(--text-secondary);
    background-color: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.pagination-btn:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.pagination-btn.active {
    background-color: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* ==========================================================================
   TYPOGRAPHY
   ========================================================================== */

.type-h1 {
    font-family: var(--font-heading);
    font-size: 48px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.type-h2 {
    font-family: var(--font-heading);
    font-size: 36px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.type-h3 {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.type-h4 {
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.type-h5 {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
}

.type-h6 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}

.type-body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.type-body-sm {
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.type-caption {
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-tertiary);
}

.type-link {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity var(--transition-fast);
}

.type-link:hover {
    opacity: 0.7;
}

/* ==========================================================================
   SIDEBAR NAVIGATION - UNIFIED COMPONENT
   Use .dashboard-sidebar or .sidebar class - both work identically
   ========================================================================== */

.sidebar,
.dashboard-sidebar {
    width: var(--sidebar-current-width, 240px);
    min-width: var(--sidebar-current-width, 240px);
    max-width: var(--sidebar-current-width, 240px);
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 200ms ease, min-width 200ms ease, max-width 200ms ease, transform 200ms ease;
}

.sidebar-header,
.sidebar-logo {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
}

.sidebar-logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.sidebar-logo-img {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.sidebar-logo-svg {
    height: 32px;
    width: auto;
    flex-shrink: 0;
}

html[data-theme="dark"] .sidebar-logo-svg,
html.theme-dark .sidebar-logo-svg,
html.dark .sidebar-logo-svg,
html[data-theme="dark"] .sidebar-logo-icon,
html.theme-dark .sidebar-logo-icon,
html.dark .sidebar-logo-icon {
    filter: invert(1);
}

/* Small icon shown only when collapsed */
.sidebar-logo-icon {
    display: none;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

/* Collapse toggle button — now a direct child of <aside>, not inside .sidebar-logo */
.sidebar-collapse-btn {
    position: absolute;
    right: 12px;
    top: 24px;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 150ms ease, background 150ms ease;
    z-index: 2;
    flex-shrink: 0;
}

.sidebar-collapse-btn svg {
    width: 14px;
    height: 14px;
    transition: transform 200ms ease;
}

.sidebar-collapse-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Show collapse button on sidebar hover or when collapsed */
.dashboard-sidebar:hover .sidebar-collapse-btn,
.sidebar:hover .sidebar-collapse-btn {
    opacity: 1;
}

/* ---- Collapsed sidebar: Claude-style seamless icon rail ---- */
.dashboard-sidebar.collapsed,
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width) !important;
    min-width: var(--sidebar-collapsed-width) !important;
    max-width: var(--sidebar-collapsed-width) !important;
    pointer-events: auto;
    transform: none;
    border-right: none !important;
    background: var(--bg-secondary, #f5f5f5) !important;
}

/* Hide ALL text labels */
.dashboard-sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-label,
.dashboard-sidebar.collapsed .nav-section-title,
.sidebar.collapsed .nav-section-title {
    display: none;
}

/* Hide logo entirely */
.dashboard-sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .sidebar-logo {
    display: none;
}

/* Nav area */
.dashboard-sidebar.collapsed .sidebar-nav,
.sidebar.collapsed .sidebar-nav {
    padding: 0 !important;
}

/* Nav items: visible icons, no backgrounds — !important to beat formatix-theme */
.dashboard-sidebar.collapsed .nav-item,
.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px 0 !important;
    gap: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: var(--text-secondary, #525252) !important;
}

.dashboard-sidebar.collapsed .nav-item:hover,
.sidebar.collapsed .nav-item:hover {
    background: transparent !important;
    color: var(--text-primary) !important;
}

.dashboard-sidebar.collapsed .nav-item.active,
.sidebar.collapsed .nav-item.active {
    background: transparent !important;
    color: var(--text-primary) !important;
}

/* Icons: 20px */
.dashboard-sidebar.collapsed .nav-icon,
.sidebar.collapsed .nav-icon {
    width: 20px;
    height: 20px;
}

/* Hide credits */
.dashboard-sidebar.collapsed .credits-display,
.sidebar.collapsed .credits-display {
    display: none;
}

/* Footer: push to bottom with gap, no border */
.dashboard-sidebar.collapsed .sidebar-footer,
.sidebar.collapsed .sidebar-footer {
    padding: 8px 0 12px !important;
    border-top: none !important;
    margin-top: auto;
}

.dashboard-sidebar.collapsed .sidebar-footer .nav-item,
.sidebar.collapsed .sidebar-footer .nav-item {
    margin-bottom: 0;
    padding: 10px 0;
}

/* Collapse/expand toggle at top of rail */
.dashboard-sidebar.collapsed .sidebar-collapse-btn,
.sidebar.collapsed .sidebar-collapse-btn {
    position: static;
    right: auto;
    top: auto;
    margin: 12px auto 8px;
    display: flex;
    opacity: 0.7;
    border: none;
    background: transparent;
    color: var(--text-secondary, #525252);
}

.dashboard-sidebar.collapsed .sidebar-collapse-btn:hover,
.sidebar.collapsed .sidebar-collapse-btn:hover {
    opacity: 1;
    background: transparent;
    color: var(--text-primary);
}

/* Dark mode: collapsed rail blends with dark content area */
html[data-theme="dark"] .dashboard-sidebar.collapsed,
html[data-theme="dark"] .sidebar.collapsed,
html.theme-dark .dashboard-sidebar.collapsed,
html.theme-dark .sidebar.collapsed,
html.dark .dashboard-sidebar.collapsed,
html.dark .sidebar.collapsed {
    background: var(--bg-primary, #1a1a1a);
}

/* Hide floating hamburger button — no longer needed with icon rail */
.sidebar-open-btn {
    position: fixed;
    top: 20px;
    left: 16px;
    z-index: 99;
    width: 32px;
    height: 32px;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: opacity 200ms ease, background 150ms ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.sidebar-open-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-open-btn svg {
    width: 18px;
    height: 18px;
}

/* No longer show floating button when collapsed (icon rail is always visible) */

/* When sidebar is collapsed, main content shifts to 48px rail width.
   Must override hardcoded 240px margin-left AND width in all page templates. */
body.sidebar-hidden .main-content,
body.sidebar-hidden .main-with-sidebar,
body.sidebar-hidden .sidebar-main-content,
body.sidebar-hidden .app-main,
body.sidebar-hidden [class*="ml-[240px]"],
body.sidebar-hidden [class*="lg:ml-[240px]"],
body.sidebar-hidden [class*="lg\\:ml-64"] {
    margin-left: var(--sidebar-collapsed-width) !important;
    width: calc(100% - var(--sidebar-collapsed-width)) !important;
    transition: margin-left 200ms ease, width 200ms ease;
}

/* Hide collapse button on mobile */
@media (max-width: 1024px) {
    .sidebar-collapse-btn {
        display: none !important;
    }
}

.logo-text {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1 1 auto;
    padding: 16px 12px;
    overflow-y: auto;
    min-height: 0;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    padding: 0 12px;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: 4px;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-active);
    color: var(--text-primary);
    font-weight: 600;
}

.nav-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 1.5;
    fill: none;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    margin-top: auto;
}

.sidebar-footer .nav-item {
    margin-bottom: 2px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid var(--border);
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-username {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-plan {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Credits Display */
.credits-display {
    padding: 12px 16px;
    margin: 16px 0;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.credits-label {
    color: var(--text-secondary);
}

.credits-value {
    font-weight: 600;
    color: var(--text-primary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

/* Credits Color Coding - Green (High: 5+), Orange (Medium: 2-4), Red (Low: <2) */
.credits-high {
    background-color: #DCFCE7;
    color: #166534 !important;
}

.credits-medium {
    background-color: #FEF3C7;
    color: #92400E !important;
}

.credits-low {
    background-color: #FEE2E2;
    color: #DC2626 !important;
}

/* Dark mode credit colors */
[data-theme="dark"] .credits-high,
.theme-dark .credits-high,
.dark .credits-high {
    background-color: rgba(34, 197, 94, 0.2);
    color: #4ADE80 !important;
}

[data-theme="dark"] .credits-medium,
.theme-dark .credits-medium,
.dark .credits-medium {
    background-color: rgba(234, 179, 8, 0.2);
    color: #FACC15 !important;
}

[data-theme="dark"] .credits-low,
.theme-dark .credits-low,
.dark .credits-low {
    background-color: rgba(239, 68, 68, 0.2);
    color: #F87171 !important;
}

/* Dark Mode Toggle Icons */
.sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon,
.theme-dark .moon-icon,
.dark .moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon,
.theme-dark .sun-icon,
.dark .sun-icon {
    display: block;
}

/* ==========================================================================
   MAIN CONTENT AREA
   ========================================================================== */

.main-with-sidebar,
.main-content {
    margin-left: var(--sidebar-current-width, 240px);
    min-height: 100vh;
    background: var(--bg-primary);
    transition: margin-left 200ms ease;
}

.content-wrapper {
    padding: 32px 48px;
    max-width: 1400px;
    margin: 0 auto;
}

/* App Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-current-width, 240px);
    min-height: 100vh;
    background: var(--bg-secondary);
    transition: margin-left 200ms ease;
}

/* ==========================================================================
   TEMPLATE CARDS
   ========================================================================== */

.template-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: all var(--transition-base);
    cursor: pointer;
}

.template-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.template-preview {
    height: 180px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.template-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.template-info {
    padding: 16px;
}

.template-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.template-meta {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* ==========================================================================
   UPLOAD AREA
   ========================================================================== */

.upload-area {
    border: 2px dashed var(--border-strong);
    border-radius: 8px;
    padding: 48px;
    text-align: center;
    background: var(--bg-secondary);
    transition: all var(--transition-base);
    cursor: pointer;
}

.upload-area:hover {
    border-color: var(--text-primary);
    background: var(--bg-tertiary);
}

.upload-area.dragover {
    border-color: var(--text-primary);
    background: var(--bg-tertiary);
}

.upload-icon {
    width: 48px;
    height: 48px;
    stroke: var(--text-tertiary);
    margin-bottom: 16px;
}

.upload-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.upload-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ==========================================================================
   AVATAR
   ========================================================================== */

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-secondary);
}

.avatar-sm {
    width: 32px;
    height: 32px;
    font-size: 12px;
}

.avatar-lg {
    width: 48px;
    height: 48px;
    font-size: 18px;
}

/* ==========================================================================
   RESPONSIVE DESIGN - Mobile First
   ========================================================================== */

/* Large tablets and small desktops */
@media (max-width: 1024px) {
    .sidebar,
    .dashboard-sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-base);
        box-shadow: var(--shadow-xl);
    }

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

    .main-with-sidebar,
    .main-content,
    .app-main {
        margin-left: 0;
    }

    .content-wrapper {
        padding: 24px 32px;
    }
}

/* Tablets */
@media (max-width: 768px) {
    .page-header {
        padding: 16px 24px;
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .page-title {
        font-size: 24px;
    }

    .main-content,
    .content-wrapper {
        padding: 16px 20px;
    }

    .cards-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .table-container {
        border-radius: var(--radius-md);
    }

    .table th,
    .table td {
        padding: 12px;
        font-size: 13px;
    }

    .btn-md {
        padding: 8px 14px;
        font-size: 13px;
    }

    .modal {
        width: 95%;
        max-height: 85vh;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    :root {
        --sidebar-width: 280px;
    }

    .page-title {
        font-size: 20px;
    }

    .main-content,
    .content-wrapper {
        padding: 12px 16px;
    }

    .card-body {
        padding: 16px;
    }

    .btn-lg {
        padding: 10px 20px;
        font-size: 15px;
        width: 100%;
    }

    .page-header-actions {
        width: 100%;
        flex-direction: column;
    }

    .page-header-actions .btn {
        width: 100%;
    }

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

    .tab {
        padding: 10px 16px;
        font-size: 13px;
        white-space: nowrap;
    }
}

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
    stroke: var(--text-primary);
    fill: none;
    stroke-width: 2;
}

@media (max-width: 1024px) {
    .mobile-menu-toggle {
        display: flex;
    }
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

@media (max-width: 1024px) {
    .sidebar-overlay {
        display: block;
    }
}

/* ==========================================================================
   UTILITY CLASSES
   Common patterns extracted from inline styles
   ========================================================================== */

/* Text Colors */
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-tertiary { color: var(--text-tertiary) !important; }
.text-muted { color: var(--text-muted) !important; }

/* Background Colors */
.bg-primary { background: var(--bg-primary) !important; }
.bg-secondary { background: var(--bg-secondary) !important; }
.bg-tertiary { background: var(--bg-tertiary) !important; }
.bg-card { background: var(--bg-card) !important; }

/* Flex Utilities */
.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Border Utilities */
.border-standard { border: 1px solid var(--border); }
.border-strong { border: 1px solid var(--border-strong); }
.border-bottom { border-bottom: 1px solid var(--border); }
.border-top { border-top: 1px solid var(--border); }

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

/* Font Weight */
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }

/* Display */
.hidden { display: none; }
.block { display: block; }
.inline-block { display: inline-block; }

/* Print Styles */
@media print {
    .sidebar,
    .dashboard-sidebar,
    .mobile-menu-toggle,
    .sidebar-overlay {
        display: none !important;
    }

    .main-with-sidebar,
    .main-content,
    .app-main {
        margin-left: 0 !important;
    }

    body {
        background: white !important;
    }
}
