:root {
    --green:  #2e7d32;
    --green-light: #e8f5e9;
    --orange: #e65100;
    --orange-light: #fff3e0;
    --red:    #c62828;
    --red-light: #ffebee;
    --blue:   #1565c0;
    --grey:   #616161;
    --border: #e0e0e0;
    --bg:     #f5f5f5;
    --card:   #ffffff;
    --text:   #212121;
    --nav-bg: #1a1a2e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

/* ── Nav ── */
nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 52px;
    background: var(--nav-bg);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.03em; }
.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    padding: 0.35rem 0.9rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
}
.nav-links a:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-links a.active { background: rgba(255,255,255,0.18); color: #fff; }

/* ── Layout ── */
main { max-width: 900px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.page-header h2 { font-size: 1.3rem; font-weight: 600; }

/* ── Stats bar ── */
.stats-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
}
.stat-number { display: block; font-size: 2rem; font-weight: 700; color: var(--blue); }
.stat-label  { display: block; font-size: 0.8rem; color: var(--grey); margin-top: 0.2rem; }

/* ── Scan box ── */
.scan-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.scan-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.6rem;
    color: var(--grey);
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.07em;
}
.scan-input {
    width: 100%;
    font-size: 1.5rem;
    padding: 0.6rem 0.9rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    outline: none;
    font-family: monospace;
    transition: border-color 0.15s;
}
.scan-input:focus { border-color: var(--blue); }

/* ── Result ── */
.result {
    margin-top: 1rem;
    padding: 0.9rem 1.1rem;
    border-radius: 8px;
    font-size: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    animation: fadeIn 0.2s ease;
}
.result.hidden { display: none; }
.result.loading { background: #f0f0f0; color: var(--grey); }

.result-in    { background: var(--green-light);  border-left: 4px solid var(--green);  color: var(--green); }
.result-out   { background: var(--orange-light); border-left: 4px solid var(--orange); color: var(--orange); }
.result-warn  { background: #fff8e1;             border-left: 4px solid #f9a825;       color: #5d4037; }
.result-error { background: var(--red-light);    border-left: 4px solid var(--red);    color: var(--red); }

.result-icon  { font-size: 1.2rem; }
.result-time  { font-size: 0.85rem; opacity: 0.8; }
.result-sub   { font-size: 0.82rem; opacity: 0.75; }
.undo-btn     { margin-top: 0.5rem; align-self: flex-start; }

/* ── Name box (scan page) ── */
.name-box { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.name-input { font-size: 1.1rem; }

/* ── Editable name cell (history page) ── */
.name-cell {
    cursor: pointer;
    min-width: 140px;
}
.name-cell:hover { background: #f0f4ff; }
.edit-hint { font-style: italic; font-size: 0.85em; }
.name-edit-input {
    width: 100%;
    padding: 0.2rem 0.4rem;
    font-size: 0.9rem;
    border: 1px solid var(--blue);
    border-radius: 4px;
    outline: none;
}
.actions-cell { white-space: nowrap; }
.btn-danger { color: var(--red) !important; }
.btn-danger:hover { background: var(--red-light) !important; }

@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateX(20px); }
}

/* ── Recent scans ── */
.recent-scans { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; }
.recent-scans h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.9rem; color: var(--grey); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.78rem; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
    text-align: left;
    padding: 0.55rem 0.75rem;
    border-bottom: 2px solid var(--border);
    color: var(--grey);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* Fixed-layout table — prevents any single cell from blowing out the layout */
.data-table {
    table-layout: fixed;
}
/* Truncate overflowing cell content with ellipsis */
.data-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Name cell may wrap (names can be long, and it has the most space) */
.data-table td.name-cell {
    white-space: normal;
    word-break: break-word;
}

.table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.badge-in   { background: var(--green-light);  color: var(--green); }
.badge-out  { background: var(--orange-light); color: var(--orange); }
.badge-warn { background: #fff8e1; color: #5d4037; }
.badge-undo { background: #e3f2fd; color: #1565c0; }

/* ── Filter bar ── */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.filter-input {
    flex: 1;
    min-width: 160px;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
}
.filter-input:focus { border-color: var(--blue); }
.filter-select {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: #fff;
    outline: none;
}

/* ── Buttons ── */
.btn {
    display: inline-block;
    padding: 0.45rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid transparent;
    transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary   { background: var(--blue);  color: #fff; }
.btn-secondary { background: var(--card);  color: var(--text); border-color: var(--border); }
.btn-ghost     { background: transparent;  color: var(--grey);  border-color: var(--border); }
.btn-lg        { padding: 0.65rem 1.5rem; font-size: 1rem; }
.btn-sm        { padding: 0.25rem 0.65rem; font-size: 0.8rem; }

/* ── Generate form ── */
.generate-form-wrap { max-width: 480px; }
.generate-form {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}
.form-row { display: flex; flex-direction: column; gap: 0.3rem; }
.form-row label { font-weight: 600; font-size: 0.9rem; }
.form-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
    width: 100%;
}
.form-input:focus { border-color: var(--blue); }
.form-input-sm { width: 120px; }
.form-hint { font-size: 0.8rem; color: var(--grey); }
.form-preview {
    padding: 0.6rem 0.9rem;
    background: #f0f4ff;
    border-radius: 6px;
    font-size: 0.88rem;
}

/* ── Utilities ── */
.mono  { font-family: monospace; font-size: 0.95em; }
.muted { color: var(--grey); }
.center { text-align: center; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
