:root {
    --ink: #16241f;
    --muted: #66736d;
    --paper: #f3efe6;
    --paper-deep: #e8e1d3;
    --card: #fffcf7;
    --line: #e3dacb;
    --line-strong: #d0c4b0;
    --palm: #16463a;
    --palm-deep: #0d2f27;
    --palm-mid: #1f5c4c;
    --palm-soft: #2d6b58;
    --palm-mist: #e8f3ee;
    --gold: #c4a35a;
    --gold-deep: #9a7a35;
    --gold-soft: #f6edd8;
    --danger: #9b2c2c;
    --danger-soft: #fdeeee;
    --ok: #1b7a52;
    --ok-soft: #e7f6ee;
    --late: #b45309;
    --late-soft: #fff4dc;
    --pending: #4d6270;
    --pending-soft: #eaf0f4;
    --excused: #3b5bdb;
    --excused-soft: #eef2ff;
    --sidebar: 272px;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(22, 36, 31, 0.04), 0 12px 28px rgba(22, 70, 58, 0.07);
    --shadow-sm: 0 1px 2px rgba(22, 36, 31, 0.05);
    --ease: 0.18s ease;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(1200px 420px at 100% -10%, rgba(196, 163, 90, 0.14), transparent 55%),
        radial-gradient(900px 380px at 0% 100%, rgba(22, 70, 58, 0.08), transparent 50%),
        var(--paper);
    line-height: 1.65;
}

a {
    color: inherit;
}

button,
input,
select,
textarea {
    font: inherit;
}

/* ——— Auth ——— */

.auth-body {
    min-height: 100vh;
    background: var(--paper);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(300px, 1.05fr) minmax(320px, 540px);
}

.auth-brand {
    background:
        linear-gradient(165deg, rgba(196, 163, 90, 0.16), transparent 42%),
        linear-gradient(180deg, var(--palm-mid), var(--palm-deep));
    color: #f4efe4;
    display: flex;
    align-items: center;
    padding: 64px 56px;
    position: relative;
}

.auth-brand::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    background: linear-gradient(180deg, var(--gold), #8d6d2e);
}

.auth-brand-inner {
    max-width: 440px;
}

.auth-mark {
    width: 72px;
    height: 72px;
    border: 1px solid rgba(196, 163, 90, 0.7);
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 32px;
    color: #f7f1e2;
    margin-bottom: 28px;
    background: rgba(255, 255, 255, 0.06);
    box-shadow: inset 0 0 0 6px rgba(13, 47, 39, 0.2);
}

img.auth-logo {
    object-fit: contain;
    background: #fff;
    padding: 8px;
    box-shadow: none;
}

.auth-kicker {
    margin: 0 0 8px;
    color: var(--gold);
    font-size: 13px;
    font-weight: 600;
}

.auth-brand h1 {
    margin: 0 0 12px;
    font-size: 48px;
    line-height: 1.1;
    color: #fffdf8;
}

.auth-tagline {
    margin: 0 0 28px;
    color: #d9cba8;
    font-size: 16px;
}

.auth-points {
    margin: 0;
    padding: 0;
    list-style: none;
    color: #e8e0d0;
}

.auth-points li {
    position: relative;
    padding-right: 18px;
    margin-bottom: 10px;
}

.auth-points li::before {
    content: "";
    position: absolute;
    right: 0;
    top: 0.75em;
    width: 8px;
    height: 2px;
    background: var(--gold);
    border-radius: 2px;
}

.auth-panel {
    display: grid;
    place-items: center;
    padding: 48px 32px;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 28px;
}

.auth-card h2 {
    margin: 0 0 8px;
    font-size: 26px;
}

.auth-lead {
    margin: 0 0 24px;
    color: var(--muted);
}

.auth-field {
    margin-bottom: 16px;
}

.auth-field .auth-input {
    margin-bottom: 0;
}

.auth-input,
select.auth-input,
textarea.auth-input {
    width: 100%;
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--ink);
    padding: 11px 14px;
    font: inherit;
    border-radius: var(--radius-sm);
    margin: 0;
    transition: border-color var(--ease), box-shadow var(--ease);
}

.auth-input:focus,
select.auth-input:focus,
textarea.auth-input:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--palm-soft);
    box-shadow: 0 0 0 3px rgba(45, 107, 88, 0.16);
}

.auth-password {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--line-strong);
    background: #fff;
    border-radius: var(--radius-sm);
}

.auth-password .auth-input {
    border: 0;
    flex: 1;
    min-width: 0;
    box-shadow: none;
}

.auth-password .auth-input:focus {
    outline: none;
    box-shadow: none;
}

.auth-password:focus-within {
    border-color: var(--palm-soft);
    box-shadow: 0 0 0 3px rgba(45, 107, 88, 0.16);
}

.auth-toggle {
    background: transparent;
    color: var(--palm);
    padding: 0 14px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.auth-toggle:hover {
    background: var(--palm-mist);
    color: var(--palm-deep);
}

.auth-submit {
    margin-top: 8px;
    padding: 12px 16px;
    font-weight: 700;
}

.auth-footnote {
    margin: 20px 0 0;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 800px) {
    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-brand {
        padding: 32px 24px 28px;
    }

    .auth-brand::after {
        inset: auto 0 0 0;
        width: auto;
        height: 4px;
        background: var(--gold);
    }

    .auth-brand h1 {
        font-size: 36px;
    }

    .auth-points {
        display: none;
    }

    .auth-panel {
        padding: 24px 16px 40px;
        align-items: start;
    }

    .auth-card {
        padding: 24px 20px;
    }
}

/* ——— Forms & buttons ——— */

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--ink);
    padding: 10px 12px;
    font: inherit;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
}

button,
.btn {
    font: inherit;
    border: 0;
    cursor: pointer;
    background: var(--palm);
    color: #f7f3ea;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transition: background var(--ease), transform var(--ease);
}

button:hover,
.btn:hover {
    background: var(--palm-deep);
}

.btn-block {
    width: 100%;
}

.btn-quiet {
    background: transparent;
    color: var(--palm);
    border: 1px solid var(--line-strong);
    padding: 10px 16px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    box-shadow: none;
    font-weight: 600;
}

.btn-quiet:hover {
    background: var(--palm-mist);
    color: var(--palm-deep);
}

.flash {
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: var(--radius-sm);
}

.flash-error {
    border-color: #f0c4c4;
    background: var(--danger-soft);
    color: var(--danger);
}

.flash-success {
    border-color: #b7d4c4;
    background: var(--ok-soft);
    color: var(--ok);
}

/* ——— App chrome ——— */

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar);
    height: 100vh;
    background:
        linear-gradient(180deg, rgba(196, 163, 90, 0.1), transparent 28%),
        linear-gradient(180deg, var(--palm), var(--palm-deep));
    color: #f4efe4;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 10px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 14px;
}

.brand-logo,
.brand-placeholder {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.08);
    display: grid;
    place-items: center;
    font-weight: 700;
    border-radius: 12px;
    border: 1px solid rgba(196, 163, 90, 0.45);
}

.brand-name {
    font-weight: 700;
    font-size: 16px;
    line-height: 1.4;
}

.brand-year {
    font-size: 12px;
    color: #d9cba8;
    margin-top: 2px;
}

.nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1;
    overflow: auto;
}

.nav-list a {
    display: block;
    text-decoration: none;
    padding: 10px 12px;
    margin-bottom: 4px;
    color: #e8e0d0;
    border-radius: 10px;
    border-right: 3px solid transparent;
    transition: background var(--ease), color var(--ease);
}

.nav-list a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.nav-list a.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-right-color: var(--gold);
    font-weight: 600;
}

.sidebar-foot {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 16px 8px 8px;
}

.user-name {
    margin: 0 0 10px;
    font-size: 14px;
    color: #d9cba8;
}

.btn-ghost {
    background: transparent;
    color: #f4efe4;
    border: 1px solid rgba(255, 255, 255, 0.22);
    width: 100%;
    box-shadow: none;
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.08);
}

.content {
    margin-right: var(--sidebar);
    padding: 24px 28px 48px;
    min-height: 100vh;
}

.content-top {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 8px;
}

.topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.menu-btn {
    background: var(--palm);
    color: #fff;
    padding: 8px 12px;
}

.page-title {
    margin: 0 0 8px;
    font-size: 30px;
    letter-spacing: -0.02em;
    line-height: 1.25;
}

.page-lead {
    margin: 0;
    color: var(--muted);
    max-width: 640px;
}

.content > .page-lead,
.content > .page-title + .page-lead {
    margin: 0 0 22px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 22px;
}

.app-date {
    margin: 0;
    color: var(--palm);
    font-size: 13px;
    font-weight: 600;
    background: var(--gold-soft);
    border: 1px solid rgba(196, 163, 90, 0.35);
    padding: 6px 12px;
    border-radius: 999px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    padding: 22px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel-grid .card + .card {
    margin-top: 0;
}

.stack > .card + .card,
.content > .card + .card {
    margin-top: 18px;
}

.card-narrow {
    max-width: 920px;
    width: 100%;
}

.card-head,
.field-label {
    margin: 0 0 14px;
    font-weight: 700;
    font-size: 15px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: right;
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

thead th {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    background: #faf6ee;
    position: sticky;
    top: 0;
}

tbody tr:hover {
    background: #fbf8f1;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.detail-table th {
    width: 180px;
    color: var(--muted);
    font-weight: 600;
    background: transparent;
}

p.empty,
.empty-state {
    color: var(--muted);
    margin: 8px 0 0;
    padding: 22px 8px;
    text-align: center;
    background: #faf7f0;
    border-radius: var(--radius-sm);
}

td.empty {
    color: var(--muted);
    text-align: center;
    background: transparent;
    padding: 28px 10px;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    background: rgba(255, 252, 247, 0.7);
    border: 1px solid var(--line);
    padding: 6px;
    border-radius: 14px;
    width: 100%;
}

.tab {
    text-decoration: none;
    padding: 8px 14px;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 10px;
    font-weight: 600;
}

.tab:hover {
    color: var(--ink);
    background: rgba(22, 70, 58, 0.06);
}

.tab.active {
    background: var(--palm);
    color: #f7f3ea;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
}

.hint {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.connect-guide {
    margin-bottom: 18px;
}

.connect-values {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 16px 0;
}

.connect-value {
    border: 1px dashed var(--line-strong);
    background: var(--paper);
    border-radius: 14px;
    padding: 14px 16px;
}

.connect-label {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.connect-data {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--palm-deep);
    word-break: break-all;
}

.connect-value .btn-quiet {
    margin-top: 10px;
}

.connect-warn {
    margin: 0 0 14px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--gold-soft);
    border: 1px solid rgba(196, 163, 90, 0.4);
    color: var(--palm-deep);
    font-size: 14px;
}

.connect-form .form-actions {
    margin-top: 8px;
}

.connect-edit {
    margin-top: 14px;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.connect-edit summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--palm);
    list-style: none;
}

.connect-edit summary::-webkit-details-marker {
    display: none;
}

.connect-edit[open] summary {
    margin-bottom: 12px;
}

.connect-reminder {
    margin-bottom: 18px;
}

.connect-steps {
    margin: 0;
    padding-right: 22px;
    color: var(--ink);
    line-height: 1.7;
}

.connect-steps li + li {
    margin-top: 6px;
}

.device-form-card .card-head {
    margin-bottom: 18px;
}

.device-form .form-grid {
    margin-bottom: 4px;
}

.device-form .auth-field {
    margin-bottom: 18px;
}

.device-form .hint {
    margin-top: 6px;
}

.device-form-enabled {
    margin: 4px 0 0;
    padding: 12px 14px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.device-form-actions {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    gap: 10px;
}

.device-form-actions .auth-submit {
    margin-top: 0;
    min-width: 120px;
}

.device-form-actions .btn-quiet {
    min-width: 120px;
    justify-content: center;
    min-height: 44px;
}

@media (min-width: 1200px) {
    .device-form .device-form-span {
        grid-column: 1 / -1;
    }
}

.logo-block {
    margin: 8px 0 20px;
}

.logo-preview {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border: 1px solid var(--line);
    background: #fff;
    display: grid;
    place-items: center;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 13px;
    border-radius: 16px;
}

.logo-preview.is-empty {
    background: var(--paper);
}

.file-input,
.file-label {
    display: inline-block;
    margin-top: 8px;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-weight: 600;
}

.choice-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 0 16px;
}

.choice-list ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.choice-list li,
.choice {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    background: #faf7f0;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 10px;
}

.preview-date {
    margin: 0 0 16px;
    color: var(--palm);
    font-weight: 600;
}

.inline-add,
.inline-rename,
.filter-row,
.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.inline-add {
    margin-bottom: 16px;
}

td .inline-add,
.row-actions .inline-add {
    margin-bottom: 0;
}

.inline-add .auth-input,
.inline-rename .auth-input,
.filter-row .auth-input {
    width: auto;
    min-width: 180px;
    margin: 0;
}

.filter-row {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card,
.stat-row > .card {
    padding: 16px 18px;
    border-top: 3px solid var(--line-strong);
}

.stat-card.is-students { border-top-color: var(--palm); }
.stat-card.is-present { border-top-color: var(--ok); }
.stat-card.is-late { border-top-color: var(--gold); }
.stat-card.is-absent { border-top-color: var(--danger); }
.stat-card.is-pending { border-top-color: #7d8b94; }
.stat-card.is-classes { border-top-color: var(--gold-deep); }
.stat-card.is-excused { border-top-color: var(--excused); }

.stat-label {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 13px;
}

.stat-value {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.stat-value a {
    color: var(--palm);
    text-decoration: none;
}

.dash-charts {
    display: grid;
    grid-template-columns: 1.05fr 1.2fr;
    gap: 18px;
    margin-bottom: 18px;
}

.donut-wrap {
    display: flex;
    align-items: center;
    gap: 28px;
    flex-wrap: wrap;
}

.donut {
    width: 176px;
    height: 176px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    box-shadow: inset 0 0 0 1px rgba(22, 70, 58, 0.06);
}

.donut-hole {
    width: 108px;
    height: 108px;
    border-radius: 50%;
    background: var(--card);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 6px var(--card);
}

.donut-hole strong {
    font-size: 28px;
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.donut-hole span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.chart-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1 1 180px;
    min-width: 180px;
}

.chart-legend li {
    display: grid;
    grid-template-columns: 12px 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--line);
}

.chart-legend li:last-child {
    border-bottom: 0;
}

.chart-legend.is-compact {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin-top: 14px;
    min-width: 0;
}

.chart-legend.is-compact li {
    display: flex;
    border: 0;
    padding: 0;
    gap: 6px;
}

.chart-swatch {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}

.chart-swatch.is-present { background: var(--ok); }
.chart-swatch.is-late { background: var(--gold); }
.chart-swatch.is-absent { background: var(--danger); }
.chart-swatch.is-pending { background: var(--pending); }
.chart-swatch.is-excused { background: var(--excused); }

.chart-name {
    font-weight: 600;
}

.chart-num {
    font-weight: 700;
}

.chart-pct {
    color: var(--muted);
    font-size: 13px;
    min-width: 2.5em;
}

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 280px;
    overflow: auto;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(72px, 110px) 1fr 48px;
    gap: 10px;
    align-items: center;
}

.bar-name {
    font-weight: 600;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    display: flex;
    height: 12px;
    background: var(--paper-deep);
    border-radius: 999px;
    overflow: hidden;
}

.bar-seg {
    display: block;
    height: 100%;
    min-width: 0;
}

.bar-meta {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-align: start;
}

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

.device-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.device-list li:last-child {
    border-bottom: 0;
}

.device-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.device-dot.badge-connected { background: var(--ok); }
.device-dot.badge-stale { background: var(--late); }
.device-dot.badge-disabled { background: #9a9186; }

.device-name {
    flex: 1;
    font-weight: 600;
}

.panel-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

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

.table-wrap a {
    color: var(--palm);
    font-weight: 600;
    text-decoration: none;
}

.table-wrap a:hover {
    text-decoration: underline;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.6;
    background: var(--pending-soft);
    color: var(--pending);
    white-space: nowrap;
}

.badge-present,
.badge-active,
.badge-connected,
.badge-matched,
.badge-sent,
.badge-ok {
    background: var(--ok-soft);
    color: var(--ok);
}

.badge-late,
.badge-stale,
.badge-queued,
.badge-sending {
    background: var(--late-soft);
    color: var(--late);
}

.badge-absent,
.badge-unmatched,
.badge-failed,
.badge-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

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

.badge-excused,
.badge-manual {
    background: var(--excused-soft);
    color: var(--excused);
}

.badge-inactive,
.badge-disabled,
.badge-skipped,
.badge-cancelled,
.badge-duplicate,
.badge-ignored_duplicate {
    background: #f1eee8;
    color: #6b6358;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.picker-list {
    min-height: 180px;
    height: 180px;
}

.composer {
    margin-bottom: 18px;
}

.template-block {
    margin-top: 18px;
}

.template-block + .template-block {
    margin-top: 16px;
}

.composer-message {
    margin: 8px 0 4px;
    padding: 16px;
    background: #faf7f0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.composer-message .auth-field {
    margin-bottom: 0;
}

.message-box {
    min-height: 160px;
    resize: vertical;
    line-height: 1.7;
    margin-bottom: 12px;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
}

button.tag-chip,
.tag-chip {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    background: #fff;
    color: var(--palm-deep);
    border: 1px solid #cfe0d8;
    box-shadow: none;
    padding: 8px 10px;
    min-height: 0;
    width: auto;
    text-align: right;
}

button.tag-chip:hover,
.tag-chip:hover {
    background: var(--palm-mist);
    color: var(--palm-deep);
}

.tag-code {
    font-size: 12px;
    font-weight: 700;
    direction: ltr;
    unicode-bidi: isolate;
}

.tag-meaning {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.preview-box {
    margin: 12px 0 16px;
    padding: 14px 16px;
    background: #faf7f0;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-sm);
}

.preview-text {
    margin: 0 0 8px;
    white-space: pre-wrap;
    line-height: 1.8;
}

.save-template {
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.composer-actions .auth-submit,
.composer-actions .btn-quiet {
    width: auto;
}

.composer-actions {
    margin-top: 16px;
}

.backdrop {
    display: none;
}

body.nav-open {
    overflow: hidden;
}

.dock {
    display: none;
}

.topbar-spacer {
    display: none;
}

@media (max-width: 1200px) {
    .stat-row {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .dash-charts {
        grid-template-columns: 1fr;
    }

    .panel-grid {
        grid-template-columns: 1fr 1fr;
    }

    .panel-grid > :last-child:nth-child(3) {
        grid-column: 1 / -1;
    }
}

@media (min-width: 1200px) {
    .form-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

/* Tablet */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(110%);
        transition: transform 0.22s ease;
        width: min(320px, 86vw);
        box-shadow: -12px 0 40px rgba(13, 47, 39, 0.18);
    }

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

    .content {
        margin-right: 0;
        padding: 16px 16px 28px;
        min-height: 100dvh;
    }

    .topbar {
        display: flex;
        position: sticky;
        top: 0;
        z-index: 12;
        margin: -16px -16px 16px;
        padding: 12px 14px calc(12px + env(safe-area-inset-top, 0px));
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
        background: var(--palm);
        color: #f7f3ea;
        box-shadow: 0 8px 24px rgba(13, 47, 39, 0.16);
        align-items: center;
        gap: 10px;
    }

    .topbar-brand {
        min-width: 0;
        flex: 1;
        text-align: right;
    }

    .topbar-brand strong {
        display: block;
        font-size: 16px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar .app-date {
        margin-top: 4px;
        display: inline-block;
        background: rgba(255, 255, 255, 0.1);
        color: #f4ead0;
        border-color: rgba(196, 163, 90, 0.35);
        font-size: 11px;
        padding: 3px 8px;
    }

    .menu-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 8px 12px;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.16);
        box-shadow: none;
        flex: 0 0 auto;
    }

    .menu-btn:hover {
        background: rgba(255, 255, 255, 0.18);
    }

    .content-top {
        display: none;
    }

    .backdrop.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(20, 16, 10, 0.45);
        z-index: 15;
    }

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

    .page-head {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 16px;
    }

    .form-actions,
    .page-head .form-actions {
        width: 100%;
    }

    .form-actions .btn,
    .form-actions .btn-quiet,
    .page-head > .btn {
        flex: 1 1 auto;
        justify-content: center;
        min-height: 44px;
    }

    .card {
        padding: 16px;
        border-radius: 14px;
    }

    .panel-grid,
    .panel-grid-2,
    .form-grid,
    .connect-values {
        grid-template-columns: 1fr;
        display: grid;
    }

    .panel-grid > :last-child:nth-child(3) {
        grid-column: auto;
    }

    .stat-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .tabs {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .tab {
        flex: 0 0 auto;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
    }

    .filter-row,
    .inline-add,
    .inline-rename {
        width: 100%;
    }

    .filter-row .auth-input,
    .inline-add .auth-input,
    .inline-rename .auth-input,
    .filter-row button,
    .inline-add button {
        width: 100%;
        min-width: 0;
        min-height: 44px;
    }

    .choice-list ul {
        grid-template-columns: 1fr 1fr;
    }

    .table-wrap {
        overflow: visible;
    }

    table.is-stacked thead {
        display: none;
    }

    table.is-stacked,
    table.is-stacked tbody {
        display: block;
        width: 100%;
    }

    table.is-stacked tr {
        display: block;
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 14px;
        padding: 12px 14px;
        margin-bottom: 10px;
        box-shadow: var(--shadow-sm);
    }

    table.is-stacked tbody tr:hover {
        background: #fff;
    }

    table.is-stacked td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        width: 100%;
        border: 0;
        border-bottom: 1px dashed var(--line);
        padding: 8px 0;
        text-align: left;
    }

    table.is-stacked td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 600;
        text-align: right;
        flex: 0 0 38%;
    }

    table.is-stacked td:first-child {
        font-size: 16px;
        font-weight: 700;
        padding-bottom: 10px;
        margin-bottom: 2px;
        border-bottom: 1px solid var(--line);
        text-align: right;
        display: block;
    }

    table.is-stacked td:first-child::before {
        display: none;
    }

    table.is-stacked td:last-child {
        border-bottom: 0;
        padding-top: 10px;
    }

    table.is-stacked td.empty,
    table.is-stacked td[colspan] {
        display: block;
        text-align: center;
        border: 0;
    }

    table.is-stacked td.empty::before,
    table.is-stacked td[colspan]::before {
        display: none;
    }

    table.is-stacked td .inline-add {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .detail-table,
    .detail-table tbody,
    .detail-table tr,
    .detail-table th,
    .detail-table td {
        display: block;
        width: 100%;
    }

    .detail-table th {
        width: auto;
        border: 0;
        padding: 10px 0 0;
        color: var(--muted);
    }

    .detail-table td {
        border-bottom: 1px solid var(--line);
        padding: 4px 0 12px;
    }

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

/* Phone */
@media (max-width: 768px) {
    .content {
        padding: 12px 12px calc(88px + env(safe-area-inset-bottom, 0px));
    }

    .topbar {
        margin: -12px -12px 12px;
        justify-content: center;
    }

    .topbar .menu-btn {
        display: none;
    }

    .topbar-brand {
        text-align: center;
    }

    .page-lead {
        font-size: 13px;
        max-width: none;
    }

    .stat-value {
        font-size: 22px;
    }

    .donut-wrap {
        justify-content: center;
    }

    .dock {
        display: flex;
        position: fixed;
        right: 0;
        left: 0;
        bottom: 0;
        z-index: 18;
        background: #fffdf8;
        border-top: 1px solid var(--line);
        box-shadow: 0 -8px 24px rgba(22, 36, 31, 0.08);
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
        justify-content: space-around;
        gap: 4px;
    }

    .dock-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        min-height: 52px;
        width: auto;
        padding: 6px 4px;
        border: 0;
        background: transparent;
        color: var(--muted);
        text-decoration: none;
        font: inherit;
        box-shadow: none;
        border-radius: 12px;
    }

    .dock-item:hover {
        background: var(--palm-mist);
        color: var(--palm);
    }

    .dock-item.active {
        color: var(--palm);
        background: var(--palm-mist);
        font-weight: 700;
    }

    .dock-label {
        font-size: 11px;
        line-height: 1.2;
        font-weight: 600;
    }

    .dock-icon {
        width: 22px;
        height: 22px;
        display: block;
        background: currentColor;
        -webkit-mask: center / contain no-repeat;
        mask: center / contain no-repeat;
    }

    .dock-dashboard {
        -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 4h7v7H4V4zm9 0h7v5h-7V4zM4 13h7v7H4v-7zm9 7v-9h7v9h-7z'/%3E%3C/svg%3E");
        mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 4h7v7H4V4zm9 0h7v5h-7V4zM4 13h7v7H4v-7zm9 7v-9h7v9h-7z'/%3E%3C/svg%3E");
    }

    .dock-classes {
        -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h10v2H4v-2z'/%3E%3C/svg%3E");
        mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h10v2H4v-2z'/%3E%3C/svg%3E");
    }

    .dock-students {
        -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 12a4 4 0 1 0-4-4 4 4 0 0 0 4 4zm0 2c-4 0-8 2-8 4v2h16v-2c0-2-4-4-8-4z'/%3E%3C/svg%3E");
        mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 12a4 4 0 1 0-4-4 4 4 0 0 0 4 4zm0 2c-4 0-8 2-8 4v2h16v-2c0-2-4-4-8-4z'/%3E%3C/svg%3E");
    }

    .dock-menu {
        -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z'/%3E%3C/svg%3E");
        mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z'/%3E%3C/svg%3E");
    }

    input[type="text"],
    input[type="password"],
    input[type="search"],
    select,
    textarea,
    .auth-input {
        font-size: 16px;
        min-height: 44px;
    }

    button,
    .btn,
    .btn-quiet,
    .auth-submit {
        min-height: 44px;
        width: 100%;
    }

    button.tag-chip,
    .tag-chip {
        width: auto;
        min-height: 0;
    }

    .form-actions {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (max-width: 800px) {
    .auth-shell {
        grid-template-columns: 1fr;
        min-height: 100dvh;
    }

    .auth-brand {
        padding: calc(20px + env(safe-area-inset-top, 0px)) 20px 18px;
    }

    .auth-brand::after {
        inset: auto 0 0 0;
        width: auto;
        height: 4px;
        background: var(--gold);
    }

    .auth-brand h1 {
        font-size: 32px;
    }

    .auth-mark {
        width: 52px;
        height: 52px;
        font-size: 24px;
        margin-bottom: 12px;
        border-radius: 14px;
    }

    .auth-points,
    .auth-tagline {
        display: none;
    }

    .auth-panel {
        padding: 22px 16px calc(28px + env(safe-area-inset-bottom, 0px));
        align-items: start;
    }

    .auth-card {
        width: 100%;
        padding: 22px 18px;
    }
}

@media print {
    .sidebar,
    .topbar,
    .dock,
    .form-actions,
    .inline-add,
    .filter-row,
    .menu-btn,
    .btn,
    .btn-quiet,
    button {
        display: none !important;
    }

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

    .card {
        box-shadow: none;
        border: 0;
        padding: 0;
    }

    table.is-stacked,
    table.is-stacked tbody,
    table.is-stacked tr,
    table.is-stacked td {
        display: revert !important;
    }
}
