:root {
    --bg: #f2ecdf;
    --panel: rgba(255, 252, 246, 0.92);
    --line: rgba(69, 53, 38, 0.14);
    --ink: #2d2115;
    --muted: #75624b;
    --primary: #b4512f;
    --primary-deep: #8b371d;
    --accent: #146a6a;
    --danger: #a23232;
    --shadow: 0 18px 50px rgba(80, 56, 28, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at top right, rgba(180, 81, 47, 0.18), transparent 28%),
        radial-gradient(circle at left center, rgba(20, 106, 106, 0.16), transparent 24%),
        linear-gradient(180deg, #f7f2e9 0%, #efe4d0 100%);
    font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", sans-serif;
}

body.modal-open {
    overflow: hidden;
}

button,
input,
select {
    font: inherit;
}

.page-shell {
    width: min(1400px, calc(100% - 32px));
    margin: 24px auto 40px;
}

.hero {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 20px;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 28px;
    background: linear-gradient(135deg, rgba(255, 249, 240, 0.92), rgba(240, 247, 245, 0.92));
    box-shadow: var(--shadow);
}

.eyebrow {
    margin: 0 0 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--primary);
}

.hero h1 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(30px, 4vw, 48px);
    line-height: 1.02;
}

.hero-copy {
    margin: 12px 0 0;
    max-width: 760px;
    line-height: 1.7;
    color: var(--muted);
}

.hero-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    align-self: start;
}

.metric-card {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.66);
}

.metric-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.metric-card strong {
    display: block;
    margin-top: 8px;
    font-size: 28px;
}

.dashboard {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.9fr);
    gap: 20px;
    margin-top: 20px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.panel-wide,
.panel-form {
    padding: 22px;
}

.panel-span-full {
    grid-column: 1 / -1;
}

.panel-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.small-title {
    font-size: 16px;
}

.panel-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar-pack {
    align-items: end;
}

.toolbar-field {
    display: grid;
    gap: 8px;
    min-width: 260px;
}

.toolbar-field span {
    font-size: 13px;
    color: var(--muted);
}

.toolbar-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    padding: 0 4px;
}

.toolbar-checkbox input {
    width: auto;
    margin: 0;
}

.toolbar-checkbox-block {
    justify-content: center;
    align-self: end;
    min-height: 48px;
    padding: 0 14px;
    border: 1px dashed rgba(69, 53, 38, 0.16);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.7);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid rgba(69, 53, 38, 0.16);
    border-radius: 14px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: rgba(20, 106, 106, 0.7);
    box-shadow: 0 0 0 4px rgba(20, 106, 106, 0.12);
    transform: translateY(-1px);
}

textarea {
    resize: vertical;
    min-height: 96px;
}

.button {
    display: inline-block;
    border: none;
    border-radius: 999px;
    padding: 11px 18px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 18px rgba(45, 33, 21, 0.14);
}

.button-primary {
    color: #fff8f2;
    background: linear-gradient(135deg, var(--primary), var(--primary-deep));
}

.button-secondary {
    color: #fff;
    background: linear-gradient(135deg, #23607a, #17485d);
}

.button-accent {
    color: #f8fffe;
    background: linear-gradient(135deg, #16806f, #0f6256);
}

.button-ghost {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(69, 53, 38, 0.12);
}

.button-danger {
    color: #fff4f4;
    background: linear-gradient(135deg, #bf4747, #8f2222);
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.78);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 960px;
}

th,
td {
    padding: 14px 12px;
    border-bottom: 1px solid rgba(69, 53, 38, 0.08);
    text-align: left;
    vertical-align: top;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(252, 245, 234, 0.96);
    color: var(--muted);
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

tbody tr:hover {
    background: rgba(20, 106, 106, 0.06);
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
}

.pager {
    display: flex;
    gap: 10px;
}

.empty-state {
    text-align: center;
    color: var(--muted);
}

.user-form {
    display: grid;
    gap: 14px;
}

.import-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
    gap: 18px;
    margin-bottom: 18px;
}

.import-form {
    display: grid;
    gap: 14px;
}

.mapping-table-wrap table {
    min-width: 1100px;
}

.mapping-status {
    font-weight: 700;
}

.mapping-status.mapped {
    color: var(--accent);
}

.mapping-status.create {
    color: var(--primary);
}

.mapping-status.requires-mapping {
    color: var(--danger);
}

.mapping-cell-input {
    min-width: 160px;
}

.user-form label {
    display: grid;
    gap: 8px;
}

.selector-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}

.selector-grid-compact {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.selector-empty {
    padding: 14px;
    border: 1px dashed rgba(69, 53, 38, 0.18);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--muted);
    line-height: 1.5;
}

.selector-chip {
    display: grid;
    gap: 6px;
    align-content: start;
    min-height: 88px;
    padding: 12px 14px;
    border: 1px solid rgba(69, 53, 38, 0.16);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.86);
    cursor: pointer;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.selector-chip:hover {
    transform: translateY(-1px);
    border-color: rgba(20, 106, 106, 0.34);
    box-shadow: 0 10px 16px rgba(45, 33, 21, 0.08);
}

.selector-chip input {
    width: auto;
    margin: 0;
}

.selector-chip-title {
    font-weight: 700;
    color: var(--ink);
}

.selector-chip-subtitle {
    font-size: 12px;
    line-height: 1.45;
    color: var(--muted);
    word-break: break-word;
}

.selector-chip-answer {
    min-height: 76px;
}

.user-form span {
    font-size: 13px;
    color: var(--muted);
}

.inline-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.status-box {
    padding: 18px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(248, 243, 233, 0.84));
}

.info-card {
    display: grid;
    gap: 8px;
    align-content: center;
    padding: 14px 16px;
    border: 1px dashed rgba(69, 53, 38, 0.18);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.72);
}

.info-card-label {
    font-size: 13px;
    color: var(--muted);
}

.info-card strong {
    font-size: 18px;
    color: var(--ink);
    word-break: break-word;
}

.status-message {
    min-height: 26px;
    margin-top: 10px;
    color: var(--muted);
}

.status-message.success {
    color: var(--accent);
}

.status-message.error {
    color: var(--danger);
}

.result-preview {
    margin: 12px 0 0;
    max-height: 260px;
    overflow: auto;
    padding: 14px;
    border-radius: 16px;
    background: #231c15;
    color: #f8efe3;
    font-size: 12px;
    line-height: 1.6;
}

.action-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mini-button {
    border: none;
    border-radius: 999px;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 12px;
}

.mini-button.edit {
    background: rgba(20, 106, 106, 0.14);
    color: #0d5656;
}

.mini-button.delete {
    background: rgba(162, 50, 50, 0.12);
    color: #8a2323;
}

.mini-button.inspect {
    background: rgba(35, 96, 122, 0.14);
    color: #17485d;
}

.private-section {
    margin-top: 18px;
}

.private-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 13px;
    color: var(--muted);
    border: 1px solid rgba(69, 53, 38, 0.16);
    background: rgba(255, 255, 255, 0.78);
}

.category-icon-editor {
    display: grid;
    justify-items: start;
    gap: 10px;
    padding: 14px;
    border: 1px dashed rgba(69, 53, 38, 0.18);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.7);
}

.category-icon-preview {
    width: 84px;
    height: 84px;
    border-radius: 18px;
    border: 1px solid rgba(69, 53, 38, 0.12);
    background: rgba(255, 255, 255, 0.96);
    object-fit: cover;
}

.category-icon-empty,
.category-icon-meta {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.category-icon-thumb {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(69, 53, 38, 0.12);
    background: rgba(255, 255, 255, 0.92);
    object-fit: cover;
}

.question-stem-preview {
    min-width: 260px;
    max-width: 420px;
}

.question-stem-preview strong {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--ink);
}

.question-stem-preview span {
    display: block;
    color: var(--muted);
    line-height: 1.6;
    word-break: break-word;
}

.modal-shell {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 20px;
}

.modal-shell[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(26, 19, 12, 0.52);
    backdrop-filter: blur(6px);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(1080px, 100%);
    max-height: calc(100vh - 40px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 28px;
    background: linear-gradient(180deg, rgba(255, 251, 245, 0.98), rgba(246, 240, 230, 0.98));
    box-shadow: 0 28px 80px rgba(36, 23, 12, 0.26);
}

.modal-card-compact {
    width: min(520px, 100%);
}

.modal-card-medium {
    width: min(760px, 100%);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 24px 18px;
    border-bottom: 1px solid rgba(69, 53, 38, 0.08);
}

.modal-header-compact {
    padding-bottom: 14px;
}

.modal-title {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(28px, 3.2vw, 36px);
    line-height: 1.06;
}

.modal-eyebrow {
    margin-bottom: 8px;
}

.modal-actions {
    flex-shrink: 0;
}

.modal-body {
    overflow: auto;
    max-height: calc(100vh - 180px);
    padding: 22px 24px 24px;
}

.modal-confirm-copy {
    margin: 0 0 18px;
    color: var(--muted);
    line-height: 1.65;
}

@media (max-width: 1100px) {
    .hero,
    .dashboard,
    .import-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .page-shell {
        width: min(100% - 20px, 1000px);
        margin-top: 10px;
    }

    .hero,
    .panel-wide,
    .panel-form {
        padding: 16px;
        border-radius: 20px;
    }

    .hero-metrics,
    .inline-fields {
        grid-template-columns: 1fr;
    }

    .panel-header,
    .table-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar,
    .form-actions,
    .pager {
        width: 100%;
    }

    .toolbar .button,
    .form-actions .button,
    .pager .button {
        flex: 1 1 auto;
    }

    .modal-shell {
        padding: 10px;
    }

    .modal-card {
        max-height: calc(100vh - 20px);
        border-radius: 20px;
    }

    .modal-header,
    .modal-body {
        padding: 16px;
    }
}
