:root {
    --bg: #0f1115;
    --panel: #1a1d24;
    --panel-2: #222631;
    --text: #e7e9ee;
    --muted: #9aa0ad;
    --line: #2c313c;
    --beer: #2e9e5b;
    --beer-2: #1f7a44;
    --cider: #7c4dff;
    --cider-2: #5e35c9;
    --mixed: #e0b400;
    --mixed-2: #b89400;
    --danger: #e5484d;
    --primary: #3b82f6;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
    gap: 10px;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar nav a {
    color: var(--muted);
    text-decoration: none;
    margin-left: 14px;
    font-size: 14px;
}
.topbar nav a:hover { color: var(--text); }
.notes-nav-toggle { display: none; }

.badge {
    font-size: 12px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--muted);
    border: 1px solid var(--line);
}
.badge-lock { background: #3a1d1f; color: #ff9a9d; border-color: #5a2a2d; }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    background: var(--panel-2);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; }

/* Buttons */
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); padding: 8px 14px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger  { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text); }
.btn-small   { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Board layout: unclaimed left, columns right */
.board {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 16px;
    padding: 16px 20px;
    align-items: start;
}
.pool, .person {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
}
.pool h2 { margin: 0 0 10px; font-size: 15px; }
.pool-summary { font-size: 13px; color: var(--text); margin: -4px 0 10px; font-weight: 600; }
.columns {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    align-content: flex-start;
    gap: 14px;
}
.person {
    flex: 0 0 220px;
    width: 220px;
    display: flex;
    flex-direction: column;
}
.person h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.person-name .swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex: 0 0 12px;
}
.person .who { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.person .count { font-size: 12px; color: var(--muted); margin-top: 8px; }

.drop-zone {
    min-height: 80px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-radius: 8px;
    padding: 6px;
    transition: background .12s, outline .12s;
    outline: 2px dashed transparent;
    flex: 1;
}
.drop-zone.dragover { background: rgba(59,130,246,.12); outline-color: var(--primary); }

/* Item cards */
.item {
    border-radius: 10px;
    padding: 9px 11px;
    color: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,.3);
    border: 1px solid rgba(255,255,255,.12);
    user-select: none;
}
.item.draggable { cursor: grab; }
.item.pingable { cursor: pointer; }
.item.dragging { opacity: .5; }
.item.pinged { position: relative; }
.item .pin {
    position: absolute;
    top: -8px;
    right: -6px;
    font-size: 14px;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,.5));
}
.item .name { font-weight: 600; font-size: 14px; }
.item .sub { font-size: 11px; opacity: .9; margin-top: 3px; line-height: 1.35; }
.item-beer  { background: linear-gradient(160deg, var(--beer),  var(--beer-2)); }
.item-cider { background: linear-gradient(160deg, var(--cider), var(--cider-2)); }
.item-mixed { background: linear-gradient(160deg, var(--mixed), var(--mixed-2)); color: #241f00; }
.item-mixed .sub { opacity: .8; }

/* Legend + chips */
.legend { display: flex; gap: 10px; padding: 0 20px 24px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; color: #fff; }
.chip-beer  { background: var(--beer); }
.chip-cider { background: var(--cider); }
.chip-mixed { background: var(--mixed); color: #241f00; }

.notes-drawer {
    position: fixed;
    z-index: 20;
    top: 50%;
    right: 0;
    display: flex;
    width: min(420px, calc(100vw - 24px));
    height: min(540px, 78vh);
    transform: translate(calc(100% - 42px), -50%);
    transition: transform .22s ease;
    background: var(--panel);
    border: 1px solid var(--line);
    border-right: 0;
    border-radius: 10px 0 0 10px;
    box-shadow: -8px 0 30px rgba(0, 0, 0, .35);
}
.notes-drawer.open, .notes-drawer:focus-within {
    transform: translate(0, -50%);
}
@media (hover: hover) {
    .notes-drawer:hover { transform: translate(0, -50%); }
}
@media (min-width: 721px) {
    /* Keep the closed tab from covering the rightmost column. */
    .board { padding-right: 62px; }
}
.notes-handle {
    flex: 0 0 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
    color: var(--text);
    background: var(--panel-2);
    border: 0;
    border-radius: 10px 0 0 10px;
    text-align: left;
    writing-mode: vertical-rl;
}
.notes-handle > span:first-child { font-weight: 600; }
.notes-close { display: none; }
.notes-panel { flex: 1; min-width: 0; overflow-y: auto; padding: 16px; }
.notes-panel label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.notes-panel textarea {
    display: block;
    width: 100%;
    min-height: 110px;
    resize: vertical;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    line-height: 1.4;
}
.notes-panel textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.notes-panel textarea[readonly] { color: var(--muted); }
.notes-footer { display: flex; justify-content: flex-end; min-height: 18px; margin-top: 5px; color: var(--muted); font-size: 12px; }

/* Banners */
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.banner-ok  { background: #14361f; color: #7ee2a0; border: 1px solid #1f5a34; }
.banner-err { background: #3a1d1f; color: #ff9a9d; border: 1px solid #5a2a2d; }
.banner-lock{ background: #3a331d; color: #f0d47a; border: 1px solid #5a4f2a; }

/* Forms */
.form-wrap, .admin-wrap { max-width: 820px; margin: 24px auto; padding: 0 16px; }

/* User page: form + info column side by side */
.user-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
    max-width: 1120px;
    margin: 24px auto;
    padding: 0 16px;
    align-items: start;
}
.user-info h2 { margin-top: 0; font-size: 16px; }
.user-info ul { margin: 0; padding-left: 18px; }
.user-info li { font-size: 13px; color: var(--muted); margin-bottom: 10px; line-height: 1.45; }
.user-info li strong { color: var(--text); }
@media (max-width: 820px) {
    .user-layout { grid-template-columns: 1fr; }
    .user-info { order: -1; }
}
.card-form fieldset {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    background: var(--panel);
}
.card-form legend { padding: 0 8px; font-weight: 600; }
.card-form label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.card-form input, .card-form select {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 9px 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    color-scheme: dark;
}
.card-form input:focus, .card-form select:focus {
    outline: none;
    border-color: var(--primary);
}
.card-form input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}
.card-form input[type="number"]::-webkit-outer-spin-button,
.card-form input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.card-form input.qty { width: 90px; }
.hint { font-size: 12px; color: var(--muted); }

.full-row {
    display: grid;
    grid-template-columns: 1fr 120px 90px 36px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.full-row input, .full-row select { margin-top: 0; }
.loose-row {
    display: grid;
    grid-template-columns: 1fr 90px 110px 36px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.loose-row input { margin-top: 0; }
.btn-remove {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    line-height: 1;
}
.form-actions { display: flex; align-items: center; gap: 14px; }

/* Admin */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 18px;
}
.card h2 { margin-top: 0; }
.card input[type="number"], .card input[type="text"] {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    color-scheme: dark;
}
.card input[type="number"]::-webkit-outer-spin-button,
.card input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.admin-user { border-top: 1px solid var(--line); padding: 14px 0; }
.admin-user:first-of-type { border-top: none; }
.admin-user-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.admin-items { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-items th, .admin-items td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.admin-items th { color: var(--muted); font-weight: 500; }

@media (max-width: 720px) {
    .board {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }
    .columns { gap: 12px; }
    .person { flex: 1 1 100%; width: auto; }
    .full-row { grid-template-columns: 1fr 100px 70px 32px; }
    .loose-row { grid-template-columns: 1fr 70px 90px 32px; }
    .topbar { padding: 10px 12px; }
    .toolbar { padding: 10px 12px; gap: 10px; }
    .legend { padding: 0 12px 20px; }
    .topbar nav { display: flex; align-items: center; gap: 12px; }
    .topbar nav a { margin-left: 0; }
    .notes-nav-toggle {
        display: inline-block;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: var(--muted);
        font-size: 14px;
    }
    .notes-nav-toggle:hover { color: var(--text); }
    /* Touch layout: only the .open class (navbar button / header) controls the drawer. */
    .notes-drawer,
    .notes-drawer:hover,
    .notes-drawer:focus-within {
        top: 0;
        right: 0;
        flex-direction: column;
        width: min(400px, 92vw);
        height: 100vh;
        height: 100dvh;
        transform: translateX(100%);
        visibility: hidden;
        box-shadow: none;
        border-right: 1px solid var(--line);
        border-radius: 10px 0 0 10px;
        transition: transform .22s ease, visibility 0s .22s;
    }
    .notes-drawer.open,
    .notes-drawer.open:hover,
    .notes-drawer.open:focus-within {
        transform: translateX(0);
        visibility: visible;
        box-shadow: -8px 0 30px rgba(0, 0, 0, .35);
        transition: transform .22s ease;
    }
    .notes-handle {
        flex: 0 0 46px;
        flex-direction: row;
        justify-content: space-between;
        padding: 0 14px;
        border-radius: 10px 0 0 0;
        writing-mode: horizontal-tb;
    }
    .notes-close { display: inline; }
    .notes-panel { padding: 12px; }
    .notes-panel textarea { min-height: 180px; }
}
