:root {
    --font-sans: Inter, "Helvetica Neue", Arial, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --color-background: #f5f7fb;
    --color-surface: #ffffff;
    --color-surface-soft: #f8f9fa;
    --color-sidebar: #222e3c;
    --color-sidebar-hover: #2d3d50;
    --color-sidebar-active: #3b7ddd;
    --color-topbar: #ffffff;
    --color-border: #dee2e6;
    --color-text: #495057;
    --color-heading: #000000;
    --color-muted: #6c757d;
    --color-primary: #3b7ddd;
    --color-primary-hover: #2f64b1;
    --color-primary-soft: #e9f1ff;
    --color-success: #1cbb8c;
    --color-warning: #fcb92c;
    --color-danger: #dc3545;
    --color-info: #17a2b8;
    --color-shadow: rgba(33, 37, 41, 0.05);
    --radius-default: 4px;
    --shadow-card: 0 0 0.875rem 0 var(--color-shadow);
    --sidebar-width: 260px;
}

html[data-theme="dark"] {
    --color-background: #19222c;
    --color-surface: #222e3c;
    --color-surface-soft: #263445;
    --color-sidebar: #111820;
    --color-sidebar-hover: #1b2632;
    --color-sidebar-active: #3b7ddd;
    --color-topbar: #222e3c;
    --color-border: #344457;
    --color-text: #d7dde5;
    --color-heading: #ffffff;
    --color-muted: #a5b1c2;
    --color-primary-soft: rgba(59, 125, 221, 0.18);
    --color-shadow: rgba(0, 0, 0, 0.22);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--color-background);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
}

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

a:hover {
    color: var(--color-primary-hover);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--color-heading);
    font-weight: 400;
    line-height: 1.2;
    margin: 0 0 0.75rem;
}

h1 {
    font-size: 1.75rem;
}

h2 {
    font-size: 1.35rem;
}

h3 {
    font-size: 1rem;
    font-weight: 600;
}

p {
    margin-top: 0;
}

img,
video {
    max-width: 100%;
}

.wrapper,
.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--color-sidebar);
    color: rgba(255, 255, 255, 0.75);
    display: flex;
    flex-direction: column;
    padding: 0;
    border: 0;
}

.sidebar-content {
    display: flex;
    min-height: 100%;
    flex-direction: column;
    padding: 0;
}

.sidebar-brand,
.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 64px;
    padding: 1.15rem 1.5rem;
    color: #ffffff;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    margin: 0;
}

.sidebar-brand:hover,
.sidebar .brand:hover {
    color: #ffffff;
    background: transparent;
}

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

.sidebar-header {
    padding: 1.25rem 1.5rem 0.45rem;
    color: rgba(255, 255, 255, 0.42);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sidebar-item {
    margin: 0;
}

.sidebar-link,
.sidebar a:not(.brand):not(.sidebar-brand) {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: rgba(255, 255, 255, 0.68);
    padding: 0.625rem 1.5rem;
    border-left: 3px solid transparent;
    border-radius: 0;
    font-weight: 400;
    min-height: 42px;
}

.sidebar-link:hover,
.sidebar a:not(.brand):not(.sidebar-brand):hover,
.sidebar-link.is-active,
.sidebar a.is-active {
    color: #ffffff;
    background: var(--color-sidebar-hover);
    border-left-color: var(--color-sidebar-active);
}

.sidebar-icon {
    width: 19px;
    text-align: center;
    opacity: 0.9;
}

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    min-height: 100vh;
}

.navbar,
.topbar {
    min-height: 64px;
    background: var(--color-topbar);
    box-shadow: 0 0 2rem 0 var(--color-shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.navbar-title {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.navbar-title strong {
    color: var(--color-heading);
    font-weight: 600;
}

.navbar-title span {
    color: var(--color-muted);
    font-size: 0.82rem;
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.content {
    flex: 1;
    padding: 2.25rem;
    overflow: auto;
}

.card {
    background: var(--color-surface);
    border: 0;
    border-radius: var(--radius-default);
    box-shadow: var(--shadow-card);
    color: var(--color-text);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.card h2,
.card h3 {
    color: var(--color-heading);
}

.stat-card,
.stats-grid .card {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.stats-grid strong,
.stat-card strong {
    color: var(--color-heading);
    font-size: 1.85rem;
    font-weight: 600;
    line-height: 1.1;
}

.stats-grid span,
.stat-card span {
    color: var(--color-muted);
}

.input,
.form-control,
.form-select,
textarea,
select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"] {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-default);
    background: var(--color-surface);
    color: var(--color-text);
    padding: 0.45rem 0.85rem;
    font: inherit;
    margin: 0.35rem 0 0.95rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

textarea.input,
textarea.form-control {
    min-height: 92px;
    resize: vertical;
}

.input:focus,
.form-control:focus,
.form-select:focus,
textarea:focus,
select:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
input[type="number"]:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 0.2rem rgba(59, 125, 221, 0.16);
}

label {
    display: inline-block;
    color: var(--color-heading);
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 36px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-default);
    padding: 0.45rem 0.85rem;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    font: inherit;
    line-height: 1.5;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.button:hover,
.btn:hover {
    background: var(--color-surface-soft);
    color: var(--color-heading);
}

.button-primary,
.btn-primary {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #ffffff;
}

.button-primary:hover,
.btn-primary:hover {
    border-color: var(--color-primary-hover);
    background: var(--color-primary-hover);
    color: #ffffff;
}

.button-secondary,
.btn-secondary {
    background: var(--color-surface-soft);
    color: var(--color-heading);
}

.button-danger,
.btn-danger {
    border-color: var(--color-danger);
    background: var(--color-danger);
    color: #ffffff;
}

.button-danger:hover,
.btn-danger:hover {
    background: #bb2d3b;
    color: #ffffff;
}

.button:disabled,
.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.theme-toggle {
    width: 38px;
    min-width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.05rem;
}

.alert {
    border: 1px solid transparent;
    border-radius: var(--radius-default);
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
}

.alert-success {
    background: rgba(28, 187, 140, 0.12);
    border-color: rgba(28, 187, 140, 0.3);
    color: var(--color-success);
}

.alert-warning {
    background: rgba(252, 185, 44, 0.14);
    border-color: rgba(252, 185, 44, 0.36);
    color: #996c00;
}

.alert-danger {
    background: rgba(220, 53, 69, 0.12);
    border-color: rgba(220, 53, 69, 0.32);
    color: var(--color-danger);
}

html[data-theme="dark"] .alert-warning {
    color: #ffd36b;
}

.table {
    width: 100%;
    border-collapse: collapse;
    color: var(--color-text);
}

.table th,
.table td {
    padding: 0.85rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: top;
}

.table th {
    color: var(--color-heading);
    font-weight: 600;
    background: var(--color-surface-soft);
}

.table tr:hover td {
    background: var(--color-surface-soft);
}

.status,
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 999px;
    padding: 0.24rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    background: var(--color-surface-soft);
    color: var(--color-muted);
}

.status-approved,
.status-active,
.status-resolved {
    background: rgba(28, 187, 140, 0.16);
    color: var(--color-success);
}

.status-pending,
.status-draft {
    background: rgba(252, 185, 44, 0.18);
    color: #9a6700;
}

.status-rejected,
.status-blocked,
.status-closed {
    background: rgba(220, 53, 69, 0.14);
    color: var(--color-danger);
}

.status-open {
    background: rgba(59, 125, 221, 0.16);
    color: var(--color-primary);
}

.muted,
.page-note,
.small-text {
    color: var(--color-muted);
}

.page-note {
    margin: 0.25rem 0 0;
    line-height: 1.55;
}

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

.actions,
.form-actions,
.vertical-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.vertical-actions {
    flex-direction: column;
}

.empty-state {
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-default);
    padding: 2rem;
    text-align: center;
    background: var(--color-surface-soft);
}

.empty-state strong {
    display: block;
    color: var(--color-heading);
    font-size: 1rem;
    margin-bottom: 0.45rem;
}

.responsive-table {
    overflow-x: auto;
}

.code-box {
    width: 100%;
    min-height: 140px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-default);
    padding: 1rem;
    background: var(--color-surface-soft);
    color: var(--color-text);
    font-family: Consolas, "Courier New", monospace;
}

@media (max-width: 992px) {
    .wrapper,
    .app-shell {
        display: block;
    }

    .sidebar {
        width: 100%;
        min-width: 0;
        min-height: auto;
    }

    .sidebar-content {
        min-height: auto;
    }

    .sidebar-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sidebar-header {
        grid-column: 1 / -1;
    }

    .main {
        min-height: auto;
    }

    .content {
        padding: 1.25rem;
    }

    .navbar,
    .topbar {
        position: static;
        padding: 0.85rem 1rem;
    }

    .page-head {
        flex-direction: column;
    }
}

@media (max-width: 560px) {
    .sidebar-nav {
        grid-template-columns: 1fr;
    }

    .navbar,
    .topbar,
    .navbar-actions {
        align-items: flex-start;
        flex-direction: column;
    }

    .theme-toggle {
        position: fixed;
        right: 1rem;
        bottom: 1rem;
        z-index: 100;
        box-shadow: var(--shadow-card);
    }
}

/* Stage39 admin polish */
.app-shell a,
.app-shell button,
.app-shell .button,
.app-shell .card,
.app-shell .admin-card,
.app-shell .table-card,
.app-shell .input,
.app-shell textarea,
.app-shell select {
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease, opacity .18s ease;
}

.app-shell .card:hover,
.app-shell .admin-card:hover,
.app-shell .table-card:hover {
    border-color: rgba(59, 125, 221, .22);
    box-shadow: 0 1rem 2rem rgba(15, 23, 42, .08);
}

.app-shell .button:hover,
.app-shell button:hover {
    transform: translateY(-1px);
}

.app-shell .button:focus-visible,
.app-shell button:focus-visible,
.app-shell a:focus-visible,
.app-shell .input:focus-visible,
.app-shell textarea:focus-visible,
.app-shell select:focus-visible {
    outline: 3px solid rgba(59, 125, 221, .22);
    outline-offset: 3px;
}
