:root {
    --ink: #1c1916;
    --muted: #6b6259;
    --paper: #f3efe8;
    --card: #fffdf9;
    --line: #e4dcd0;
    --teal: #1f6f6a;
    --teal-dark: #165753;
    --copper: #c56a32;
    --amber: #b45309;
    --blue: #1d4ed8;
    --green: #157a4b;
    --red: #b42318;
    --sidebar: #171410;
    --shadow: 0 12px 32px rgba(28, 25, 22, 0.08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: Manrope, "Segoe UI", sans-serif;
    background: var(--paper);
    color: var(--ink);
}

a { color: var(--teal-dark); }
button, input, select, textarea { font: inherit; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 280px;
    background: var(--sidebar);
    color: #f6efe6;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sidebar-close {
    display: none;
    border: 0; background: #2a241f; color: #f6efe6;
    width: 40px; height: 40px; border-radius: 10px;
    font-size: 24px; line-height: 1; cursor: pointer;
}
.sidebar-logout { display: none; justify-content: center; }
.sidebar-backdrop { display: none; }
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; }
.brand-mark {
    width: 44px; height: 44px; border-radius: 12px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--copper), var(--teal));
    font-weight: 800;
    flex: 0 0 44px;
}
.brand-logo {
    width: 44px; height: 44px; border-radius: 12px;
    object-fit: contain; background: #fff; flex: 0 0 44px;
}
.brand strong { display: block; font-size: 16px; }
.brand small { color: #c4b8aa; }
.side-nav { display: flex; flex-direction: column; gap: 6px; }
.side-nav a {
    color: #e8ddd0; text-decoration: none;
    padding: 11px 14px; border-radius: 12px;
}
.side-nav a:hover, .side-nav a.is-active { background: #2a241f; color: #fff; }
.side-user { margin-top: auto; display: flex; gap: 10px; align-items: center; color: #d9cfc3; }
.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: #3a322b; display: grid; place-items: center; font-weight: 700;
}
.side-user small { display: block; color: #b6aa9d; }

.main { flex: 1; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 22px 28px 8px;
}
.topbar-title h1 { margin: 0; font-size: 28px; letter-spacing: -0.03em; }
.topbar-title p { margin: 4px 0 0; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-btn { display: none; border: 0; background: #fff; border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.content { padding: 16px 28px 40px; }

.flash { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; }
.flash-success { background: #e5f6ec; color: #0f5132; }
.flash-error { background: #fde8e6; color: #7a1c16; }
.flash-info { background: #e8f1ff; color: #1e3a8a; }

.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.stat strong { display: block; font-size: 32px; line-height: 1; }
.stat span { color: var(--muted); }

.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.btn, .ghost-btn {
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 12px; padding: 10px 16px; text-decoration: none;
    border: 0; cursor: pointer; font-weight: 700;
}
.btn { background: var(--teal); color: #fff; }
.btn:hover { background: var(--teal-dark); }
.btn-copper { background: var(--copper); }
.btn-danger { background: var(--red); color: #fff; }
.ghost-btn { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-sm { padding: 7px 11px; font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 10px 8px; }
td { padding: 12px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
.table-wrap { overflow: auto; }

.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; }
.amber { background: #ffedd5; color: var(--amber); }
.blue { background: #dbeafe; color: var(--blue); }
.green { background: #dcfce7; color: var(--green); }
.muted { background: #ece7df; color: #57534e; }
.teal { background: #d7f3ef; color: var(--teal-dark); }

.user-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-top: 14px;
}
.user-tile {
    display: grid;
    justify-items: center;
    text-align: center;
    gap: 6px;
    padding: 16px 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card);
    cursor: pointer;
    color: inherit;
    font: inherit;
    min-height: 148px;
}
.user-tile:hover, .user-tile:focus-visible {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 18%, transparent);
}
.user-tile .avatar {
    width: 44px; height: 44px; font-size: 18px;
    background: linear-gradient(135deg, var(--copper), var(--teal));
    color: #fff;
}
.user-tile strong { font-size: 14px; line-height: 1.25; }
.user-tile small { color: var(--muted); font-size: 12px; }
.user-tile-roles { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.user-tile-roles .badge { font-style: normal; padding: 2px 8px; font-size: 11px; }
.user-dialog {
    width: min(480px, calc(100vw - 24px));
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 20px;
    background: var(--card);
    color: inherit;
    box-shadow: var(--shadow);
}
.user-dialog::backdrop { background: rgba(23, 20, 16, .45); }
.user-dialog-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.user-dialog-head h2 { margin: 0; font-size: 20px; }
.user-dialog-head .help { margin: 4px 0 0; }
.ticket-card { display: block; text-decoration: none; color: inherit; }
.ticket-card h3 { margin: 0 0 8px; }
.ticket-meta { color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.type-pc { border-left: 6px solid #2563eb; }
.type-office { border-left: 6px solid #7c3aed; }
.type-refill { border-left: 6px solid var(--teal); }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 600; }
.form input, .form select, .form textarea {
    width: 100%; border: 1px solid var(--line); border-radius: 12px;
    padding: 11px 12px; background: #fff;
}
.form textarea { min-height: 110px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subdomain-field { display: flex; align-items: center; gap: 8px; }
.subdomain-field input { flex: 1 1 auto; min-width: 0; }
.subdomain-field em {
    color: var(--muted);
    font-style: normal;
    font-weight: 700;
    white-space: nowrap;
}
.org-switch { display: grid; gap: 6px; padding: 0 0 8px; }
.org-switch span { color: #c4b8a8; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.org-switch a { color: #f6efe6; text-decoration: none; font-size: 14px; font-weight: 600; }
.org-switch a.is-current { color: #9be2db; }
.help { color: var(--muted); font-weight: 500; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--copper) 24%, transparent), transparent 32%),
        radial-gradient(circle at 80% 0%, color-mix(in srgb, var(--teal) 22%, transparent), transparent 30%),
        var(--paper);
    padding: 24px;
}
.login-card { width: min(440px, 100%); }
.login-card h1 { margin: 0 0 6px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-max { margin-top: 18px; display: grid; gap: 10px; }
.login-max .btn { width: 100%; }
.help-list { color: var(--muted); padding-left: 18px; display: grid; gap: 8px; }
.help-list a { font-weight: 700; }
.login-brand { display: flex; justify-content: center; margin-bottom: 16px; }
.login-logo { max-width: 180px; max-height: 72px; object-fit: contain; }
.login-mark {
    width: 64px; height: 64px; border-radius: 18px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--copper), var(--teal));
    color: #fff; font-weight: 800; font-size: 22px;
}
.login-preview-wrap { border-radius: 18px; overflow: hidden; border: 1px solid var(--line); }
.login-preview { min-height: 520px; padding: 28px 16px; }
.logo-current img { max-height: 64px; max-width: 180px; object-fit: contain; }

.theme-light {
    --ink: #172033;
    --muted: #5b6677;
    --paper: #eef3f8;
    --card: #ffffff;
    --line: #d5deea;
    --sidebar: #152033;
    --shadow: 0 12px 32px rgba(23, 32, 51, 0.08);
}
.theme-dark {
    --ink: #f4efe6;
    --muted: #b7b0a6;
    --paper: #121418;
    --card: #1c2026;
    --line: #313843;
    --sidebar: #0d0f12;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
.theme-dark .tab { background: #1c2026; }
.theme-dark .inline-add input,
.theme-dark .inline-add select,
.theme-dark .chip {
    background: #15181d;
    color: #f4efe6;
    border-color: #313843;
}
.theme-dark .form input,
.theme-dark .form select,
.theme-dark .form textarea,
.theme-dark .ghost-btn,
.theme-dark .menu-btn {
    background: #15181d;
    color: #f4efe6;
    border-color: #313843;
}
.theme-dark .comment { background: #15181d; }
.theme-dark .flash-success { background: #16351f; color: #b7f0c8; }
.theme-dark .flash-error { background: #3a1613; color: #ffc4be; }
.theme-contrast {
    --ink: #111111;
    --muted: #222222;
    --paper: #ffffff;
    --card: #ffffff;
    --line: #111111;
    --sidebar: #111111;
    --shadow: none;
    --radius: 8px;
}
.theme-contrast .btn { border-radius: 8px; }
.theme-contrast .login-page {
    background: #fff;
}

.bell { position: relative; text-decoration: none; font-size: 20px; }
.bell em {
    position: absolute; top: -8px; right: -10px;
    background: var(--copper); color: #fff;
    border-radius: 999px; font-size: 11px; min-width: 18px;
    padding: 2px 5px; text-align: center; font-style: normal;
}
.comments { display: grid; gap: 12px; }
.comment { background: #f7f3ec; border-radius: 12px; padding: 12px 14px; }
.comment strong { display: block; }
.comment small { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

.check-set, .check-row { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.check-set { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.check-set legend { font-weight: 700; padding: 0 6px; }
.check-item { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check-item input { width: auto; }
.executor-sections-form { border: 1px solid var(--line); border-radius: 14px; padding: 14px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 12px; border-radius: 12px;
    background: var(--card); border: 1px solid var(--line);
    color: inherit; text-decoration: none; font-weight: 700;
}
.tab em { font-style: normal; color: var(--muted); font-weight: 600; }
.tab.is-active { background: var(--teal); color: #fff; border-color: transparent; }
.tab.is-active em { color: rgba(255,255,255,.8); }

.compact-page { display: grid; gap: 12px; }
.compact-card { padding: 14px 16px; }
.compact-card h2 { margin: 0 0 10px; font-size: 17px; }
.compact-head { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 10px; }
.compact-head h2 { margin: 0; }
.inline-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-add input, .inline-add select {
    width: auto; min-width: 0; flex: 1 1 140px;
    padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.inline-add .btn, .inline-add .ghost-btn { flex: 0 0 auto; }
.grow { flex: 1; }
.split-row { display: flex; gap: 8px; align-items: center; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: #f4efe6; border: 1px solid var(--line);
    border-radius: 999px; padding: 4px 6px 4px 10px; margin: 0;
}
.chip-x { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; }
.compact-table th, .compact-table td { padding: 7px 6px; }
.compact-table .empty, .compact-table .help { padding: 10px 6px; text-align: left; }
.group-title { margin: 14px 0 6px; font-size: 14px; color: var(--muted); }
.nowrap { white-space: nowrap; }

.hidden { display: none !important; }

.bottom-nav { display: none; }
.scroll-row { display: flex; flex-wrap: wrap; gap: 8px; }

@media (max-width: 960px) {
    html, body { overflow-x: hidden; }
    body.nav-open { overflow: hidden; }

    .grid-3, .grid-2, .form-row { grid-template-columns: 1fr; }
    .user-tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .user-dialog {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        overflow: auto;
        padding: 16px;
    }

    .sidebar {
        position: fixed;
        z-index: 30;
        transform: translateX(-110%);
        transition: transform .2s ease;
        width: min(320px, 88vw);
        padding-top: max(16px, env(safe-area-inset-top));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    .sidebar.is-open { transform: none; }
    .sidebar-close { display: inline-flex; align-items: center; justify-content: center; }
    .sidebar-logout { display: inline-flex; margin-top: 8px; background: #2a241f; color: #f6efe6; border-color: #3a322b; }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 25;
        background: rgba(23, 20, 16, .48);
    }
    .sidebar-backdrop.is-open { display: block; }

    .topbar {
        position: sticky;
        top: 0;
        z-index: 15;
        padding: 12px 16px 10px;
        padding-top: max(12px, env(safe-area-inset-top));
        background: color-mix(in srgb, var(--paper) 92%, transparent);
        backdrop-filter: blur(12px);
        gap: 10px;
    }
    .topbar-title h1 { font-size: 20px; }
    .topbar-title p { display: none; }
    .topbar-logout { display: none; }
    .menu-btn { display: none; }
    .bell { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }

    .content {
        padding: 12px 16px 28px;
        padding-bottom: calc(88px + env(safe-area-inset-bottom));
    }

    .card { padding: 16px; }
    .btn, .ghost-btn { min-height: 44px; }
    .btn-sm { min-height: 36px; }

    input, select, textarea { font-size: 16px; }
    .form .btn { width: 100%; }

    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar > .btn { width: 100%; }
    .word-break, .help a { word-break: break-word; }
    .scroll-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -4px;
        padding: 2px 4px 6px;
    }
    .scroll-row::-webkit-scrollbar { display: none; }
    .scroll-row .btn,
    .scroll-row .ghost-btn { flex: 0 0 auto; white-space: nowrap; }

    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -4px 4px;
        padding: 2px 4px 6px;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { flex: 0 0 auto; min-height: 40px; }

    .ticket-card .toolbar { align-items: flex-start; }
    .ticket-card h3 { font-size: 16px; }

    .inline-add { width: 100%; }
    .inline-add input,
    .inline-add select { flex: 1 1 100%; min-width: 0; }
    .inline-add .btn,
    .inline-add .ghost-btn { width: 100%; }
    .split-row { flex-wrap: wrap; align-items: stretch; }
    .split-row > form:last-child { margin-left: auto; }
    .split-row > form:last-child .ghost-btn { width: auto; min-width: 44px; }

    .table-cards thead { display: none; }
    .table-cards tbody { display: grid; gap: 10px; }
    .table-cards tr {
        display: grid;
        gap: 8px;
        padding: 14px;
        border: 1px solid var(--line);
        border-radius: 14px;
        background: var(--card);
    }
    .table-cards td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        border: 0;
        padding: 0;
    }
    .table-cards td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 700;
        flex: 0 0 38%;
    }
    .table-cards td[data-label=""] { justify-content: flex-end; }
    .table-cards td[data-label=""]::before { display: none; }
    .table-cards td:has(form) { flex-direction: column; align-items: stretch; }
    .table-cards .actions { width: 100%; }
    .table-cards .actions input { flex: 1 1 auto; min-width: 0; }
    .table-cards .badge { flex-wrap: wrap; }

    .login-preview { min-height: 420px; padding: 20px 12px; }
    .login-page { padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
    .login-card h1 { font-size: 24px; }

    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 18;
        background: var(--card);
        border-top: 1px solid var(--line);
        padding: 6px 8px max(8px, env(safe-area-inset-bottom));
        justify-content: space-around;
        gap: 4px;
    }
    .bottom-nav a,
    .bottom-nav button {
        position: relative;
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-height: 52px;
        border: 0;
        background: transparent;
        color: var(--muted);
        text-decoration: none;
        font: inherit;
        cursor: pointer;
    }
    .bottom-nav em { font-style: normal; font-size: 11px; font-weight: 700; }
    .bottom-nav a.is-active,
    .bottom-nav button.is-active { color: var(--teal-dark); }
    .bottom-nav .nav-dot {
        position: absolute;
        top: 4px;
        right: calc(50% - 22px);
        min-width: 16px;
        padding: 1px 4px;
        border-radius: 999px;
        background: var(--copper);
        color: #fff;
        font-size: 10px;
        font-style: normal;
        text-align: center;
    }
}

@media (max-width: 520px) {
    .topbar-title h1 {
        font-size: 18px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 52vw;
    }
    .check-set, .check-row { flex-direction: column; align-items: flex-start; }
}

.theme-dark .sidebar-close,
.theme-dark .sidebar-logout { background: #1c2026; color: #f4efe6; border-color: #313843; }
.theme-dark .bottom-nav { background: #1c2026; }
.theme-dark .sidebar-backdrop { background: rgba(0, 0, 0, .55); }
