:root {
    --ink: #28232f;
    --muted: #716b7c;
    --line: #e9e3ee;
    --paper: #fffdf9;
    --soft: #f7f2f8;
    --wine: #7b2948;
    --wine-dark: #5d1d36;
    --green: #2f7d5a;
    --red: #b84242;
    --shadow: 0 18px 50px rgba(54, 39, 65, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: #fbf8fc;
    display: grid;
    grid-template-columns: 260px 1fr;
}

body.setup-page {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    padding: 24px;
}

.setup-box {
    width: min(680px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.setup-box h1 {
    margin: 0 0 12px;
}

.setup-box p {
    color: var(--muted);
    line-height: 1.6;
}

.setup-box pre {
    overflow: auto;
    padding: 14px;
    background: var(--soft);
    border-radius: 8px;
}

a {
    color: inherit;
}

.sidebar {
    min-height: 100vh;
    padding: 28px 20px;
    background: #ffffff;
    border-right: 1px solid var(--line);
    position: sticky;
    top: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 34px;
}

.brand > span {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    background: var(--wine);
    color: #fff;
    border-radius: 8px;
    font-weight: 700;
}

.brand strong {
    font-size: 18px;
}

.menu-button {
    display: none;
}

nav {
    display: grid;
    gap: 8px;
}

nav a,
.study-toolbar a {
    text-decoration: none;
    padding: 12px 14px;
    border-radius: 8px;
    color: var(--muted);
}

nav a.active,
nav a:hover,
.study-toolbar a.selected,
.study-toolbar a:hover {
    background: var(--soft);
    color: var(--wine);
}

.mini-stats {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.content {
    width: min(1120px, 100%);
    padding: 40px;
}

.page-head {
    margin-bottom: 24px;
}

.page-head p {
    margin: 0 0 8px;
    color: var(--wine);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0;
}

.page-head h1 {
    margin: 0;
    font-size: 36px;
}

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

.stats-grid article,
.panel,
.form-panel,
.table-panel,
.done-state {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.stats-grid article {
    padding: 22px;
}

.stats-grid span {
    display: block;
    color: var(--muted);
    margin-bottom: 8px;
}

.stats-grid strong {
    font-size: 34px;
}

.actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 20px 0 28px;
}

.button,
button {
    appearance: none;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    padding: 11px 16px;
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

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

button.success {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}

button.danger {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}

.panel,
.form-panel,
.table-panel,
.done-state {
    padding: 22px;
    margin-bottom: 22px;
}

.panel-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.panel-title h2,
.form-panel h2,
.done-state h2 {
    margin: 0;
}

.group-list {
    display: grid;
    gap: 10px;
}

.group-list a {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    text-decoration: none;
    background: var(--paper);
}

.group-list span,
small,
.empty,
.done-state p {
    color: var(--muted);
}

form {
    display: grid;
    gap: 14px;
}

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

.search-panel form {
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px) auto;
    align-items: end;
}

label {
    display: grid;
    gap: 7px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    font: inherit;
    color: var(--ink);
    background: #fff;
}

textarea {
    resize: vertical;
}

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

th,
td {
    text-align: left;
    padding: 14px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
}

td strong,
td small {
    display: block;
}

.row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.row-actions form {
    display: inline;
}

.row-actions a,
.row-actions button,
.panel-title a {
    color: var(--wine);
    background: transparent;
    border: 0;
    padding: 0;
    text-decoration: none;
    font-size: 14px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.fichas-list {
    display: grid;
    gap: 8px;
}

.ficha-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.ficha-main {
    min-width: 0;
}

.ficha-meta,
.ficha-text {
    display: flex;
    align-items: baseline;
    gap: 12px;
    min-width: 0;
}

.ficha-meta {
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 12px;
}

.meta-group {
    color: #2463a6;
}

.meta-review {
    color: #b84242;
}

.ficha-text strong,
.ficha-text span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ficha-text strong {
    flex: 0 1 44%;
}

.ficha-text span {
    flex: 1 1 auto;
    color: var(--muted);
}

.study-card {
    background: var(--paper);
    border: 1px solid #e7ddcf;
    border-radius: 8px;
    box-shadow: 0 16px 40px rgba(64, 48, 38, 0.12);
    padding: 24px;
    position: relative;
}

.study-card::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 64px;
    border-top: 1px solid rgba(123, 41, 72, 0.18);
}

.study-card.small h3 {
    margin: 18px 0 12px;
}

.study-card.small p {
    color: var(--muted);
}

.card-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 28px;
}

.study-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.study-stage {
    display: grid;
    place-items: start center;
}

.study-stage .study-card {
    width: min(720px, 100%);
}

.card-face small {
    color: var(--wine);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 12px;
}

.card-face h2 {
    font-size: 30px;
    line-height: 1.25;
    margin: 10px 0 22px;
}

.card-face p {
    font-size: 21px;
    line-height: 1.5;
}

details {
    margin-top: 18px;
}

summary {
    cursor: pointer;
    color: var(--wine);
    font-weight: 700;
}

.review-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 24px;
}

.alert {
    padding: 14px 16px;
    margin-bottom: 18px;
    background: #fff3f3;
    color: #8c2424;
    border: 1px solid #f0cccc;
    border-radius: 8px;
}

.notice {
    padding: 14px 16px;
    margin-bottom: 18px;
    background: #effaf4;
    color: #225f42;
    border: 1px solid #ccebd9;
    border-radius: 8px;
}

.help-text {
    margin: 0 0 12px;
    color: var(--muted);
}

.sample-csv {
    overflow: auto;
    margin: 0;
    padding: 14px;
    background: var(--soft);
    border-radius: 8px;
    border: 1px solid var(--line);
}

@media (max-width: 820px) {
    body {
        display: block;
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: 0;
        height: 54px !important;
        max-height: 54px;
        overflow: hidden;
        position: sticky;
        z-index: 10;
        padding: 6px 10px 5px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        align-self: start;
    }

    .sidebar.menu-open {
        height: auto !important;
        max-height: none;
        overflow: visible;
    }

    .brand {
        justify-content: space-between;
        margin-bottom: 0;
    }

    .brand > span {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .brand strong {
        font-size: 15px;
    }

    .menu-button {
        width: 38px;
        height: 34px;
        display: grid;
        place-content: center;
        gap: 5px;
        margin-left: auto;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: #fff;
        padding: 0;
        cursor: pointer;
    }

    .menu-button span {
        width: 18px;
        height: 2px;
        background: var(--wine);
        border-radius: 999px;
    }

    nav {
        display: none;
        grid-template-columns: 1fr;
        gap: 3px;
        margin-top: 6px;
    }

    nav a {
        padding: 6px 9px;
        font-size: 13px;
        line-height: 1.15;
    }

    .sidebar.menu-open nav {
        display: grid;
    }

    .mini-stats {
        display: none;
    }

    .content {
        padding: 8px 16px 24px;
    }

    .stats-grid,
    .review-actions {
        grid-template-columns: 1fr;
    }

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

    .group-list a,
    .card-meta,
    .ficha-row,
    .ficha-meta,
    .ficha-text {
        display: grid;
    }

    .ficha-row {
        gap: 10px;
    }

    .ficha-row .row-actions {
        justify-content: flex-start;
    }

    .page-head h1 {
        font-size: 30px;
    }
}
