:root {
    --bg: #f3efe7;
    --panel: #fffdf8;
    --ink: #1f2933;
    --muted: #62707c;
    --accent: #9c6644;
    --accent-strong: #6f3e21;
    --danger: #9b2226;
    --success: #2d6a4f;
    --border: #d8ccb8;
    --shadow: 0 18px 40px rgba(31, 41, 51, 0.08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Nunito Sans", "Trebuchet MS", Verdana, sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at top, #fff8ee 0, var(--bg) 55%, #e9ddcd 100%);
}

a { color: inherit; }

.site-header,
.page-shell,
.page-head,
.toolbar,
.button-row,
.status-line,
.detail-grid,
.keg-list,
.inline-form,
.stack-form {
    display: flex;
}

.site-header {
    justify-content: space-between;
    align-items: center;
    gap: 0.7rem;
    padding: 0.75rem 1.2rem;
    background: rgba(255, 253, 248, 0.92);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.site-header nav,
.toolbar,
.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.site-nav a,
.site-nav button {
    text-decoration: none;
}

.brand {
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.brand-logo {
    height: 2rem;
    width: auto;
    display: block;
}

.page-shell {
    flex-direction: column;
    gap: 0.9rem;
    width: min(1080px, calc(100% - 2rem));
    margin: 1rem auto 2rem;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.8rem;
    box-shadow: var(--shadow);
}

.auth-card {
    max-width: 480px;
    margin-inline: auto;
    width: 100%;
}

.stack-form {
    flex-direction: column;
    gap: 0.75rem;
}

label { display: grid; gap: 0.4rem; }

input,
select,
textarea,
button,
.button {
    min-height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 0.6rem 0.8rem;
    font: inherit;
}

button,
.button {
    background: var(--accent);
    color: #fff;
    border: none;
    text-decoration: none;
    cursor: pointer;
}

.button.secondary {
    background: transparent;
    color: var(--accent-strong);
    border: 1px solid var(--accent-strong);
}

.flash-stack { display: grid; gap: 0.75rem; }

.flash {
    padding: 0.9rem 1rem;
    border-radius: 12px;
}

.flash-success { background: #dcefe3; color: var(--success); }
.flash-error { background: #f6ddde; color: var(--danger); }
.flash-info { background: #ede7dc; color: var(--ink); }

.muted-copy {
    color: var(--muted);
}

.history-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}

.history-toolbar input[type="search"] {
    width: 100%;
}

.event-type-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    background: var(--panel);
    transition: background 0.12s, color 0.12s;
    user-select: none;
}

.filter-chip:has(input:checked) {
    background: var(--accent-strong);
    color: #fff;
    border-color: var(--accent-strong);
}

.filter-chip input[type="checkbox"] {
    display: none;
    min-height: unset;
}

.event-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.event-keg_created      { background: #d6ecff; color: #0b4f6c; }
.event-status_changed   { background: #ede7dc; color: #6f3e21; }
.event-beer_assigned    { background: #d8f3dc; color: #1b4332; }
.event-keg_moved        { background: #fff1d6; color: #7c4a00; }
.event-repair_flag_set  { background: #ffe0e2; color: #9b2226; }
.event-repair_flag_cleared { background: #d8f3dc; color: #1b4332; }

.history-notes {
    vertical-align: middle;
    min-width: 0;
    white-space: normal;
}

.history-notes-content {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    min-height: 1.5rem;
}

.history-arrow {
    color: var(--muted);
    font-weight: 700;
}

.event-note {
    color: var(--muted);
    font-size: 0.88rem;
}

.td-nowrap {
    white-space: nowrap;
}

.page-head {
    justify-content: space-between;
    align-items: end;
    gap: 0.75rem;
}

.toolbar { flex-wrap: wrap; }

.table-wrap {
    overflow-x: auto;
}

.restore-shell {
    display: grid;
    gap: 1rem;
}

.restore-warning {
    padding: 0.9rem 1rem;
    border-radius: 12px;
    background: #fff1d6;
    border: 1px solid #f0c36a;
    color: #6f3e21;
}

.restore-details {
    display: grid;
    gap: 0.85rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin: 0;
}

.restore-details dt {
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.restore-details dd {
    margin: 0.2rem 0 0;
    font-weight: 700;
}

.restore-log {
    margin: 0;
    padding: 1rem;
    min-height: 220px;
    max-height: 480px;
    overflow-y: auto;
    border-radius: 14px;
    background: #1f2933;
    color: #f6f0e5;
    border: 1px solid #2f3b46;
    font-size: 0.92rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.keg-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.keg-table th,
.keg-table td {
    text-align: left;
    padding: 0.55rem 0.65rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.keg-table th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    user-select: none;
}

.keg-table th.sortable:hover {
    color: var(--accent-strong);
    background: rgba(156,102,68,0.05);
}

.keg-table th.sort-active {
    color: var(--accent-strong);
}

.sort-arrow {
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

.sort-arrow.muted {
    opacity: 0.35;
}

.keg-table tr:last-child td {
    border-bottom: none;
}

.keg-list {
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.6rem;
}

.keg-card {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 0.7rem 0.8rem;
    border-radius: 12px;
    background: #fffaf0;
    border: 1px solid var(--border);
}

.compact-list {
    margin-top: 0.5rem;
}

.compact-card h2 {
    margin: 0 0 0.25rem;
    font-size: 1.05rem;
}

.compact-card p {
    margin: 0.1rem 0;
}

.status-line {
    gap: 0.5rem;
    flex-wrap: wrap;
}

.status-inline {
    font-weight: 700;
    align-items: center;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 800;
    padding: 0.45rem 0.7rem;
    background: #fff4df;
    border: 1px solid var(--border);
    border-radius: 999px;
}

.status-pill.small {
    min-height: 28px;
    padding: 0.2rem 0.55rem;
    font-size: 0.85rem;
}

.status-danger {
    background: #ffe0e2;
    color: #9b2226;
}

.status-dot {
    line-height: 1;
}

.status-badge,
.repair-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.92rem;
    font-weight: 700;
}

.status-in_use { background: #d8f3dc; color: #1b4332; }
.status-clean { background: #d6ecff; color: #0b4f6c; }
.status-cleaning { background: #c9f2ff; color: #0b7285; }
.status-dirty { background: #ffe8cc; color: #9c6644; }
.status-decommissioned { background: #dee2e6; color: #343a40; }
.repair-badge { background: #ffd6a5; color: #9b2226; }

.detail-grid {
    flex-wrap: wrap;
    gap: 0.45rem 0.9rem;
}

.detail-grid > div {
    min-width: 180px;
    display: grid;
    gap: 0.2rem;
}

.compact-grid > div {
    min-width: 150px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.45rem;
}

.stat-card {
    padding: 0.65rem 0.75rem;
}

.stat-number {
    margin: 0.2rem 0 0;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--accent-strong);
}

.checkbox-line {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    width: fit-content;
}

.checkbox-line input {
    min-height: auto;
    width: 1.1rem;
    height: 1.1rem;
    padding: 0;
}

.repair-note-wrapper {
    display: grid;
}

details > summary {
    cursor: pointer;
    font-weight: 700;
    padding: 0.2rem 0;
}

details[open] > summary {
    margin-bottom: 0.6rem;
}

.eyebrow {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-size: 0.8rem;
}

.inline-form { display: inline-flex; }

/* ========================================
   USER MANAGEMENT STYLES
   ======================================== */

/* Admin Header: Contains title and action buttons
   - Displays title on left, action buttons on right
   - Uses flexbox with space-between to align items apart
   - gap: spacing between child elements (title and buttons)
   - align-items: vertically centers items
*/
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.admin-header h1 {
    margin: 0;
    font-size: 1.75rem;
}

/* Users Table: Displays all users in a structured format
   - Uses semantic HTML table for tabular data
   - border-collapse: removes double borders between cells
   - width: 100%: stretches to fill container
*/
.users-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

/* Table Header: Column titles
   - background: light background to distinguish from data rows
   - border-bottom: underline separator
   - font-weight: 700 makes text bold
   - text-align: left aligns text to the left
   - padding: internal spacing around text
   - color: uses muted color for subtle appearance
*/
.users-table thead {
    background: rgba(158, 137, 115, 0.06);
    border-bottom: 2px solid var(--border);
}

.users-table th {
    font-weight: 700;
    text-align: left;
    padding: 0.75rem 1rem;
    color: var(--muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Table Body Rows: Data rows with alternating backgrounds
   - border-bottom: subtle divider between rows
   - padding: internal spacing for content
   - :hover background: highlights row on mouse hover for better UX
*/
.users-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background-color 0.2s ease;
}

.users-table tbody tr:hover {
    background: rgba(156, 102, 68, 0.03);
}

/* Table Data Cells: Individual cell styling
   - padding: internal spacing for content
   - vertical-align: top aligns content to the top of cells
*/
.users-table td {
    padding: 0.9rem 1rem;
    vertical-align: middle;
}

/* Actions Cell: Cell containing edit/delete buttons
   - display: flex with gap creates horizontal button layout
   - flex-wrap: wrap allows buttons to wrap on small screens
   - gap: spacing between buttons
*/
.actions-cell {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Badge: Visual indicator for roles/status
   - display: inline-flex centers content
   - background: light color from theme
   - color: text color from theme
   - padding: internal spacing
   - border-radius: 999px creates pill shape (large radius = rounded ends)
   - font-size: smaller than normal text
   - font-weight: 700 makes text bold
   - white-space: nowrap prevents text from wrapping
*/
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(156, 102, 68, 0.1);
    color: var(--accent-strong);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
}

/* Form Card: Container for forms
   - max-width: limits form width for readability
   - margin: auto centers the form on the page
*/
.form-card {
    max-width: 600px;
    margin: 0 auto;
}

/* Form Section: Groups related form elements
   - margin-bottom: spacing between form sections
*/
.form-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
    border-bottom: none;
}

/* Divider Class: Visual separator between sections
   - Adds margin and padding for breathing room
*/
.divider {
    border-top: 1px solid var(--border);
    padding-top: 2rem;
    margin-bottom: 2rem;
}

/* Form Section Heading: Subsection titles
   - font-size: 1.2rem makes it slightly larger
   - margin: sets spacing around the heading
   - color: uses the muted color for visual hierarchy
*/
.form-section h2 {
    font-size: 1.2rem;
    margin: 0 0 1rem 0;
    color: var(--ink);
}

/* Alert Messages: Notifications for errors/success
   - padding: internal spacing
   - border-radius: rounded corners
   - margin-bottom: spacing below alert
   - display: grid creates consistent layout
*/
.alert {
    padding: 0.9rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    display: grid;
    border: 1px solid transparent;
}

/* Alert Error State
   - background: light red background
   - color: dark red text
   - border-color: darker red border for definition
*/
.alert-error {
    background: #f6ddde;
    color: var(--danger);
    border-color: #e5c0c2;
}

.alert-success {
    background: #dcefe3;
    color: var(--success);
    border-color: #b8e6c5;
}

/* Empty State: Message when no data to display
   - text-align: centers the message
   - color: muted color for subtle appearance
   - padding: internal spacing
   - font-size: slightly smaller than normal
*/
.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 2rem;
    font-size: 0.95rem;
}

.empty-state a {
    color: var(--accent-strong);
    font-weight: 700;
    text-decoration: none;
}

.empty-state a:hover {
    text-decoration: underline;
}

/* Button Styles: Primary, secondary, danger, small variants
   - background: background color
   - color: text color
   - border: outline style
   - padding: internal spacing
   - border-radius: rounded corners
   - cursor: pointer: shows clickable state
   - transition: smooth color change on hover
   - font-weight: 700 makes text bold
*/
.button.primary {
    background: var(--accent);
    color: #fff;
}

.button.primary:hover {
    background: var(--accent-strong);
}

.button.secondary {
    background: transparent;
    color: var(--accent-strong);
    border: 1px solid var(--accent-strong);
}

.button.secondary:hover {
    background: rgba(111, 62, 33, 0.08);
}

/* Danger Button: For delete actions
   - background: red color indicating destructive action
   - Provides clear visual warning
*/
.button.danger {
    background: var(--danger);
    color: #fff;
    border: none;
}

.button.danger:hover {
    background: #7a1921;
}

/* Small Button: Compact button for table actions
   - min-height: reduced from default 44px
   - padding: reduced padding
   - font-size: slightly smaller text
*/
.button.small {
    min-height: 36px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

/* Inline Form: Allows form inside table/text
   - display: inline-flex puts form on same line as text
   - gap: spacing between form elements
   - margin: sets distance from surrounding content
*/
.inline-form {
    display: inline-flex;
    gap: 0.5rem;
    margin: 0;
}

.inline-form button {
    margin: 0;
}

/* Button Row: Horizontal layout of multiple buttons
   - display: flex creates horizontal layout
   - gap: spacing between buttons
   - flex-wrap: wrap allows buttons to wrap on small screens
   - margin-top: spacing above button row
*/
.button-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

/* Responsive Design for Mobile Devices
   - Adjusts layout when screen is smaller than 600px
   - Stacks elements vertically instead of horizontally
   - Full width usage for better mobile experience
*/
@media (max-width: 600px) {
    .page-head,
    .keg-card {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    /* Keep top nav compact on phones: single-row, horizontally scrollable. */
    .site-header {
        padding: 0.45rem 0.65rem;
        gap: 0.45rem;
        align-items: stretch;
    }

    .site-header nav {
        display: flex;
        flex-wrap: nowrap;
        gap: 0.4rem;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.15rem;
        scrollbar-width: thin;
    }

    .site-header nav a,
    .site-header nav button {
        flex: 0 0 auto;
        white-space: nowrap;
        min-height: 32px;
        padding: 0.35rem 0.6rem;
        font-size: 0.86rem;
        border-radius: 999px;
    }

    .site-header nav .inline-form {
        flex: 0 0 auto;
    }

    .site-header nav .inline-form button {
        min-height: 32px;
        padding: 0.35rem 0.6rem;
    }

    .brand {
        font-size: 1rem;
    }

    .brand-logo {
        height: 1.6rem;
    }

    /* Larger touch targets on mobile */
    input,
    select,
    textarea,
    button,
    .button {
        min-height: 44px;
        font-size: 1rem;
    }

    .stack-form {
        gap: 1rem;
    }

    label {
        gap: 0.5rem;
        font-size: 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .keg-table th,
    .keg-table td {
        padding: 0.45rem 0.5rem;
        font-size: 0.92rem;
    }

    /* Admin header stacks on mobile
       - title above buttons instead of side-by-side
    */
    .admin-header {
        flex-direction: column;
        align-items: stretch;
    }

    /* Table optimization for mobile
       - Consider showing less information on small screens
       - Can be enhanced with responsive table libraries if needed
    */
    .users-table {
        font-size: 0.9rem;
    }

    .users-table th,
    .users-table td {
        padding: 0.6rem 0.75rem;
    }

    /* Button row stacks vertically on mobile
       - Each button takes full width
    */
    .button-row {
        flex-direction: column;
    }

    .button-row .button {
        width: 100%;
    }

    /* Form sections and auth card take full width on mobile */
    .form-card,
    .auth-card {
        max-width: 100%;
        padding: 1.25rem 1rem;
    }

    /* Actions in table become full width buttons on mobile */
    .actions-cell {
        flex-direction: column;
    }

    .actions-cell .button {
        width: 100%;
    }

    .history-toolbar {
        gap: 0.5rem;
    }

    .event-type-filters {
        gap: 0.35rem;
    }

    .filter-chip {
        font-size: 0.76rem;
        padding: 0.2rem 0.55rem;
    }
}
