:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #2b2118;
  --muted: #8a7a68;
  --accent: #c2571b;
  --accent-dark: #9a4213;
  --line: #e8ddcf;
  --warn-bg: #fff4e5;
  --warn-ink: #8a4b00;
  --err-bg: #fdecea;
  --err-ink: #a1271f;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.45;
}
h1, h2, h3, h4 { margin: 0.4em 0; }
.muted { color: var(--muted); font-size: 0.9em; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%; max-width: 360px; box-shadow: 0 4px 18px rgba(0,0,0,.06); }
.login-card h1 { text-align: center; }
.login-card .muted { text-align: center; margin-bottom: 16px; }

/* header + tabs */
.app-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 1.05em; }
.tabs { display: flex; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 47px; z-index: 9; }
.tab { flex: 1 0 auto; border: 0; background: none; padding: 12px 14px; font-size: 0.92em; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 14px; max-width: 900px; margin: 0 auto; }
.tab-panel { animation: fade .15s ease-in; }
@keyframes fade { from { opacity: .4; } to { opacity: 1; } }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

label { display: block; font-size: 0.85em; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 1em; color: var(--ink); }
input, select, textarea {
  width: 100%; padding: 9px 10px; margin-top: 4px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 1em; font-family: inherit; background: #fff; color: var(--ink);
}
input[type="checkbox"] { width: auto; }
.search { margin-bottom: 10px; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 9px 14px; border-radius: 8px; font-size: 0.95em; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:active { background: var(--accent-dark); }
.btn.small { padding: 6px 10px; font-size: 0.85em; }
.btn.danger { color: var(--err-ink); border-color: #f3c1bc; }
#btn-logout { background: transparent; border-color: #5a4a3a; color: #fff; }

.error { background: var(--err-bg); color: var(--err-ink); border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 0.9em; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 0.9em; }
.banner { background: var(--warn-bg); color: var(--warn-ink); padding: 12px 14px; font-size: 0.95em; border-bottom: 1px solid var(--line); }

.list-item { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 8px; cursor: pointer; }
.list-item:hover { border-color: var(--accent); }
.list-item .sub { color: var(--muted); font-size: 0.88em; }
.list-item .right { float: right; text-align: right; }

table.data { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; font-size: 0.92em; }
table.data th, table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.data th { background: #f4ece1; font-size: 0.82em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.data input, table.data select { padding: 6px 8px; margin: 0; }

.item-row { display: grid; grid-template-columns: 1fr 90px 90px 36px; gap: 8px; margin-bottom: 8px; align-items: end; }
.item-row label { margin: 0; }
.ing-row { display: grid; grid-template-columns: 1fr 90px 90px 36px; gap: 8px; margin-bottom: 8px; align-items: end; }
.ing-row label { margin: 0; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 1.1em; cursor: pointer; padding: 6px 0; width: 100%; }

.allergy { color: var(--err-ink); font-weight: 700; }
.total { font-weight: 700; font-size: 1.1em; }

/* kitchen sheet */
.k-dish { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 4px; border-bottom: 2px solid var(--line); }
.k-dish .name { font-size: 1.5em; font-weight: 700; }
.k-dish .counts { font-size: 1.6em; font-weight: 800; color: var(--accent); white-space: nowrap; }
.k-dish .counts small { font-size: 0.5em; color: var(--muted); font-weight: 400; }
.k-section { font-size: 1.1em; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 4px; }
.k-week { font-size: 1.8em; font-weight: 800; margin: 6px 0 12px; }

/* bag tags */
.tags-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.bag-tag { border: 2px dashed var(--ink); border-radius: 8px; padding: 14px; background: #fff; page-break-inside: avoid; }
.bag-tag h3 { font-size: 1.3em; margin: 0 0 4px; }
.bag-tag ul { margin: 6px 0; padding-left: 20px; }

/* route planner */
.stop-list { list-style: none; padding: 0; margin: 12px 0; }
.stop-list li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.stop-num { font-size: 1.7em; font-weight: 800; color: var(--accent); min-width: 1.4em; line-height: 1.1; }
.warn-card { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 12px 14px; margin-top: 12px; }
.warn-card ul { margin: 6px 0 0; padding-left: 20px; }

/* print */
/* The hidden attribute must always win over display rules above (e.g. .login-wrap's flex). */
[hidden] { display: none !important; }

@media print {
  #view-login, .app-header, .tabs, .no-print, #db-warning { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .tab-panel { display: none !important; }
  body[data-print="kitchen"] #panel-kitchen { display: block !important; }
  body[data-print="tags"] #panel-tags { display: block !important; }
  body[data-print="route"] #panel-route { display: block !important; }
  body[data-print="route"] #panel-route > .card { display: none !important; }
  .card { border: 0; box-shadow: none; }
  .k-dish .name { font-size: 2em; }
  .k-dish .counts { font-size: 2.4em; }
}
