/* Base look shared with the popup dashboard (public/dashboard/styles.css) —
   duplicated rather than shared so the 5S suite stays a fully standalone
   app with no path dependency on the dashboard folder. Keep the shared
   rules (:root through the responsive block) in sync by eye if either
   changes; the 5S-specific rules are appended below the shared block. */
:root {
  --maroon: #8a2a24;
  --maroon-dark: #661e19;
  --maroon-light: #a83c32;
  --gold: #c99a3f;
  --gold-light: #e4c878;
  --ink: #1c1714;
  --muted: #6b6259;
  --border: #ece4da;
  --paper: #fdfbf8;
  --shadow-sm: 0 1px 2px rgba(40, 20, 12, .05);
  --shadow-md: 0 4px 16px rgba(58, 26, 18, .08);
  --shadow-lg: 0 16px 40px rgba(58, 26, 18, .14);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --good: #2f7a3a;
  --warn: #b5791f;
  --bad: #b23a2f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #f9f5ee 0%, #f3ede2 100%);
  -webkit-font-smoothing: antialiased;
}
#app { min-height: 100vh; }

::selection { background: var(--gold-light); color: var(--maroon-dark); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ddd2c2; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold); }

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 16px 28px;
  background: #fffdfa;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.topbar::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--maroon) 0%, var(--gold) 50%, var(--maroon) 100%);
  opacity: .7;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; cursor: pointer; flex: 0 0 auto; transition: opacity .15s ease; }
.topbar .brand:hover { opacity: .75; }
.topbar .brand-mark { width: 28px; height: 28px; display: block; flex: 0 0 auto; }
.topbar h1 {
  font-family: 'Roboto Slab', Georgia, serif; font-size: 18px; font-weight: 800; margin: 0;
  letter-spacing: .01em;
  background: linear-gradient(100deg, var(--maroon) 30%, var(--maroon-light) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbar .crumbs { font-size: 13px; color: var(--muted); flex: 1 1 auto; min-width: 0; }
.topbar .crumbs a { color: var(--maroon); text-decoration: none; cursor: pointer; font-weight: 600; }
.topbar .crumbs a:hover { color: var(--gold); }
.topbar .right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); flex: 0 0 auto; }
.topbar .right span { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.container { max-width: 980px; margin: 0 auto; padding: 32px 24px 56px; }

.login-wrap {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
  background:
    radial-gradient(circle at 15% 12%, rgba(201, 154, 63, .16), transparent 45%),
    radial-gradient(circle at 88% 82%, rgba(138, 42, 36, .14), transparent 45%),
    linear-gradient(180deg, #faf6ee 0%, #f1e8da 100%);
}
.login-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 5px;
  background: linear-gradient(90deg, var(--maroon), var(--gold));
}
.login-card .login-brand { display: flex; justify-content: center; margin-bottom: 22px; }
.login-card .login-brand img { width: 100%; max-width: 220px; height: auto; display: block; }
.login-card h1 { font-size: 19px; margin: 0 0 4px; font-weight: 700; }
.login-card p.hint { font-size: 13px; color: var(--muted); margin: 0 0 22px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 18px 0 7px; color: #40372f; }
label:first-child { margin-top: 0; }

.hint { font-size: 13px; color: #8a7f72; line-height: 1.55; margin: 8px 0 18px; }
.hint:last-child { margin-bottom: 0; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], input[type="tel"],
input[type="date"],
select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #ddd3c4; border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input::placeholder, textarea::placeholder { color: #b3a897; }
input:hover, select:hover, textarea:hover { border-color: #cbbda5; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible {
  outline: none; border-color: var(--maroon); box-shadow: 0 0 0 3px rgba(138, 42, 36, .14);
}
textarea { resize: vertical; min-height: 60px; }
.checkbox-row { display: flex; align-items: center; gap: 9px; margin: 14px 0; }
.checkbox-row input { width: auto; accent-color: var(--maroon); }
.checkbox-row label { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 18px; min-height: 40px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform .12s ease, box-shadow .15s ease, opacity .15s ease, background-color .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--maroon-light), var(--maroon-dark)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: 0 6px 18px rgba(138, 42, 36, .28); }
.btn-secondary { background: #fff; color: #4a3f34; border-color: #ddd3c4; }
.btn-secondary:hover { background: #faf5ec; border-color: var(--gold); }
.btn-danger { background: #fff; color: #b23a2f; border-color: #f0c4bd; }
.btn-danger:hover { background: #fdf1ef; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; min-height: 32px; font-size: 13px; }

.btn-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.error-msg { color: #b23a2f; font-size: 13px; margin: 10px 0 0; font-weight: 500; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-top: 20px; }
.card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px;
  cursor: pointer; transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
  position: relative;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--gold-light); }
.card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.card p { margin: 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.card .meta {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.card .meta-row { font-size: 12.5px; color: var(--ink); line-height: 1.4; }

.section-head { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin: 4px 0 22px; }
.section-head h2 { font-size: 20px; margin: 0; font-weight: 800; font-family: 'Roboto Slab', Georgia, serif; color: var(--maroon-dark); }

.empty { color: #a89b89; font-size: 14px; margin-top: 18px; }

table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 13px; }
.table-scroll { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 4px 14px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid #f1ebe1; white-space: nowrap; }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr.is-clickable { cursor: pointer; }
tr.is-clickable:hover td { background: #fbf7ef; }

.stat-row { display: flex; gap: 16px; margin: 18px 0; flex-wrap: wrap; }
.stat {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 20px 16px;
  min-width: 100px; flex: 1 1 100px; position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
}
.stat::before {
  content: ""; position: absolute; top: 0; left: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--gold), var(--maroon));
}
.stat .num { font-size: 25px; font-weight: 800; font-family: 'Roboto Slab', Georgia, serif; color: var(--maroon-dark); }
.stat .label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(30, 18, 12, .45); backdrop-filter: blur(2px); display: flex;
  align-items: center; justify-content: center; z-index: 1000; padding: 16px;
}
.modal-box {
  background: var(--paper); border-radius: var(--radius-lg); padding: 28px; width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-box h2 { margin: 0 0 4px; font-size: 18px; font-weight: 800; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; justify-content: flex-end; flex-wrap: wrap; }

fieldset {
  border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px 20px 20px; margin: 24px 0;
  background: #fffefb;
}
fieldset legend {
  font-size: 12px; font-weight: 700; padding: 3px 10px; color: var(--maroon-dark);
  background: linear-gradient(135deg, #fbeee0, #f6e2c8); border-radius: 999px; letter-spacing: .02em;
}

.tag {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: linear-gradient(135deg, #fbeee0, #f3ddb8); color: var(--maroon-dark); margin-left: 8px;
  overflow-wrap: anywhere;
}

.list-item {
  display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 10px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 18px; margin-top: 12px;
  transition: box-shadow .18s ease, border-color .18s ease;
}
.list-item:hover { box-shadow: var(--shadow-md); border-color: var(--gold-light); }
.list-item .info { min-width: 0; }
.list-item .info h3 { margin: 0 0 3px; font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.list-item .info p { margin: 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.list-item .actions { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 640px) {
  .container { padding: 22px 16px; }
  .topbar { padding: 12px 16px; }
  .topbar .right span { display: none; }
  .section-head { align-items: flex-start; }
  .section-head .btn-row, .section-head > div { width: 100%; }
  .section-head .btn-row .btn, .section-head > div .btn { flex: 1 1 auto; }
  .list-item { flex-direction: column; align-items: stretch; }
  .list-item .actions .btn { flex: 1 1 auto; }
  .modal-box { padding: 20px; }
  .stat { flex: 1 1 calc(50% - 10px); }
}

/* ---- 5S-specific ------------------------------------------------- */

.due-badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em;
}
.due-badge::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.due-badge.is-ok { background: #eaf5ec; color: var(--good); }
.due-badge.is-due-soon { background: #faf1de; color: var(--warn); }
.due-badge.is-overdue, .due-badge.is-never { background: #fbeae7; color: var(--bad); }

.score-pill {
  display: inline-flex; align-items: center; justify-content: center; min-width: 34px;
  font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; font-family: 'Roboto Slab', Georgia, serif;
}
.score-pill.s-hi { background: #eaf5ec; color: var(--good); }
.score-pill.s-mid { background: #faf1de; color: var(--warn); }
.score-pill.s-lo { background: #fbeae7; color: var(--bad); }
.score-pill.s-none { background: #f1ebe1; color: var(--muted); }

.category-block {
  background: #fffefb; border: 1px solid var(--border); border-radius: var(--radius-md);
  margin: 18px 0; overflow: hidden;
}
.category-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 14px 18px; background: linear-gradient(135deg, #fbeee0, #f6e2c8);
  cursor: pointer; user-select: none;
}
.category-head h3 { margin: 0; font-size: 14px; font-weight: 800; color: var(--maroon-dark); }
.category-head .category-sub { font-size: 11.5px; color: #7a6a4d; }
.category-head .category-avg { font-size: 12px; font-weight: 700; color: var(--maroon-dark); flex: 0 0 auto; }
.category-body { padding: 14px 18px 18px; display: none; }
.category-block.is-open .category-body { display: block; }
.category-block.is-open .category-head-caret { transform: rotate(90deg); }
.category-head-caret { display: inline-block; margin-left: 8px; transition: transform .15s ease; font-size: 11px; color: var(--maroon-dark); }

.checklist-item { border-top: 1px solid var(--border); padding: 14px 0; }
.checklist-item:first-child { border-top: none; padding-top: 0; }
.checklist-item-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.checklist-item-label { flex: 1 1 220px; font-size: 13.5px; font-weight: 600; margin: 0; }
.checklist-item-remove { flex: 0 0 auto; }

.star-rating { display: inline-flex; gap: 3px; }
.star-btn {
  width: 28px; height: 28px; border: none; background: none; cursor: pointer; padding: 0;
  color: #ddd0ba; transition: color .12s ease, transform .1s ease;
}
.star-btn svg { width: 100%; height: 100%; fill: currentColor; }
.star-btn:hover { transform: scale(1.1); }
.star-btn.is-filled { color: var(--gold); }

.checklist-item-note { margin-top: 8px; }
.checklist-item-note textarea { min-height: 44px; font-size: 13px; }

.photo-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.photo-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }

.add-item-row { margin-top: 12px; display: flex; gap: 8px; }
.add-item-row input { flex: 1 1 auto; }

.audit-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 10px; }
.audit-photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }

.trend-chart-wrap {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 16px 18px 12px; margin-top: 4px;
}
.trend-chart { display: block; width: 100%; height: auto; }
.trend-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.trend-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.trend-swatch { width: 10px; height: 10px; border-radius: 999px; flex: 0 0 auto; }
.trend-table-toggle { margin-top: 12px; font-size: 13px; }
.trend-table-toggle summary { cursor: pointer; color: var(--maroon); font-weight: 600; }
.trend-table-toggle summary:hover { color: var(--gold); }
.trend-table-toggle .table-scroll { margin-top: 10px; }
