/* ─── sf-web styles ───────────────────────────────────────────── */

/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f4f6f9;
  --surface:   #ffffff;
  --border:    #d9e0ea;
  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --danger:    #dc2626;
  --danger-h:  #b91c1c;
  --success:   #16a34a;
  --warning:   #d97706;
  --text:      #1e293b;
  --text-sub:  #64748b;
  --radius:    6px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

#app { min-height: 100%; }

/* ─── Layout ──────────────────────────────────────────────────── */
.shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: #1e293b;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.sidebar__brand {
  padding: 1.25rem 1.25rem 0.75rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.3px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar__brand small {
  display: block;
  font-size: .65rem;
  font-weight: 400;
  color: var(--text-sub);
  margin-top: .15rem;
}

.sidebar__nav {
  flex: 1;
  padding: .75rem 0;
}

.sidebar__nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .75rem 1.25rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: .9375rem;
  transition: background .15s, color .15s;
}

.sidebar__nav a:hover  { background: rgba(255,255,255,.06); color: #f1f5f9; }
.sidebar__nav a.active { background: rgba(37,99,235,.25); color: #93c5fd; font-weight: 600; }

.sidebar__nav .icon { width: 1.2rem; text-align: center; font-size: 1.05rem; }

.sidebar__footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .75rem;
  color: var(--text-sub);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar__footer .role-badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.role-badge.admin    { background: rgba(220,38,38,.25);  color: #fca5a5; }
.role-badge.edit     { background: rgba(217,119,6,.25);  color: #fcd34d; }
.role-badge.readonly { background: rgba(100,116,139,.25); color: #94a3b8; }

/* Main content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .875rem;
}

.topbar__title { font-weight: 600; color: var(--text); }

/* Content area */
.content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

/* ─── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card__header h2 { font-size: 1.125rem; font-weight: 600; }
.card__header h3 { font-size: 1rem; font-weight: 600; }

/* ─── Tables ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

thead th {
  text-align: left;
  padding: .6rem .75rem;
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-sub);
  white-space: nowrap;
}

tbody td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: #f8fafc; }

/* Sortable hint */
th[data-sort] { cursor: pointer; user-select: none; }

/* ─── Forms ───────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: .3rem;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--text-sub);
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  max-width: 420px;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

textarea { resize: vertical; min-height: 80px; }

input.inline, select.inline {
  display: inline-block;
  width: auto;
  min-width: 120px;
}

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .85rem;
  border: none;
  border-radius: var(--radius);
  font-size: .8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  text-decoration: none;
  line-height: 1.3;
}

.btn:active { transform: translateY(1px); }

.btn-primary  { background: var(--primary);   color: #fff; }
.btn-primary:hover { background: var(--primary-h); }

.btn-danger   { background: var(--danger);    color: #fff; }
.btn-danger:hover  { background: var(--danger-h); }

.btn-ghost    { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover  { background: #f1f5f9; }

.btn-sm       { padding: .3rem .6rem; font-size: .75rem; }

.btn--outline { background: transparent; border: 1px solid rgba(255,255,255,.2); color: #94a3b8; }
.btn--outline:hover { background: rgba(255,255,255,.08); color: #e2e8f0; border-color: rgba(255,255,255,.35); }

/* ─── Sidebar logout ──────────────────────────────────────────── */
.sidebar__logout {
  padding: .5rem 1.25rem .75rem;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar__logout .btn {
  width: 100%;
  justify-content: center;
  padding: .45rem;
  font-size: .75rem;
}

.btn + .btn   { margin-left: .35rem; }

/* ─── Status badges ──────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.badge-pass   { background: rgba(22,163,74,.12);  color: #16a34a; }
.badge-fail   { background: rgba(220,38,38,.12);  color: #dc2626; }
.badge-ok     { background: rgba(37,99,235,.12);  color: #2563eb; }
.badge-warn   { background: rgba(217,119,6,.12);  color: #d97706; }

/* ─── Stats filter bar ────────────────────────────────────────── */
.filter-bar {
  margin-bottom: 1rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-group {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.filter-group label {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--text-sub);
  white-space: nowrap;
}
.filter-btns {
  display: flex;
  gap: .35rem;
}
.filter-dates {
  display: flex;
  align-items: flex-end;
  gap: .75rem;
  margin-top: .5rem;
  flex-wrap: wrap;
}
.filter-dates .form-group { margin-bottom: 0; }
.filter-dates input[type="date"] {
  padding: .35rem .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .8125rem;
  background: var(--surface);
  color: var(--text);
}

/* ─── Stats cards ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: .25rem;
}

.stat-card__label {
  font-size: .75rem;
  color: var(--text-sub);
}

/* ─── Flash / toast messages ─────────────────────────────────── */
.flash {
  padding: .65rem 1rem;
  border-radius: var(--radius);
  font-size: .8125rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  animation: fadeIn .2s ease;
}

.flash-success { background: rgba(22,163,74,.1);  color: #166534; border: 1px solid rgba(22,163,74,.25); }
.flash-error   { background: rgba(220,38,38,.1);  color: #991b1b; border: 1px solid rgba(220,38,38,.25); }
.flash-info    { background: rgba(37,99,235,.1);  color: #1e40af; border: 1px solid rgba(37,99,235,.25); }

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

/* ─── Login page ──────────────────────────────────────────────── */
.login-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  z-index: 100;
}

.login-card {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 2rem 2.5rem;
  width: 100%;
  max-width: 380px;
}

.login-card h2 {
  text-align: center;
  margin-bottom: 1.5rem;
  font-size: 1.25rem;
}

.login-card .btn { width: 100%; justify-content: center; padding: .6rem; }

.login-logo {
  text-align: center;
  font-size: 2rem;
  margin-bottom: .5rem;
}

/* ─── Settings: step description grid ─────────────────────────── */
.step-grid {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: .5rem .75rem;
  align-items: center;
}

.step-grid .step-num {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text-sub);
  text-align: right;
}

/* ─── User table actions ─────────────────────────────────────── */
.row-actions { white-space: nowrap; }

/* ─── Empty state ─────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-sub);
  font-size: .9rem;
}

/* ─── Item detail (Find Item) ──────────────────────────────────── */
.item-detail__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.item-detail__header h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

.item-detail__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.item-detail__field {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.item-detail__label {
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--text-sub);
}

.item-detail__value {
  font-size: .9375rem;
  font-weight: 500;
  color: var(--text);
}

.item-detail__actions {
  margin-top: .5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ─── Steps summary ──────────────────────────────────────────── */
.steps-summary {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.steps-summary h4 {
  font-size: .9375rem;
  font-weight: 600;
  margin-bottom: .75rem;
  color: var(--text);
}

.steps-table {
  font-size: .8125rem;
}

.steps-table td {
  vertical-align: top;
  padding: .5rem .65rem;
}

.steps-data-cell {
  max-width: 320px;
  overflow-x: auto;
}

.steps-data-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.steps-data-list li {
  padding: .15rem 0;
  border-bottom: 1px solid rgba(0,0,0,.04);
}

.steps-data-list li:last-child {
  border-bottom: none;
}

.steps-data-key {
  font-size: .75rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(37,99,235,.08);
  padding: .05rem .3rem;
  border-radius: 3px;
}

.steps-data-val {
  font-size: .8125rem;
  color: var(--text);
}

.steps-data-num {
  font-weight: 600;
  color: var(--success);
}

.steps-data-str {
  color: var(--text);
}

.steps-data-obj {
  font-size: .75rem;
  color: var(--text-sub);
  word-break: break-all;
}

.steps-raw {
  font-size: .75rem;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .5rem;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
  color: var(--text);
}

.text-small {
  font-size: .75rem;
}

.text-muted {
  color: var(--text-sub);
  font-style: italic;
}

/* ─── Upload result ──────────────────────────────────────────── */
.upload-result {
  padding: 1rem;
  border-radius: var(--radius);
}
.upload-result--ok {
  background: rgba(22,163,74,.06);
  border: 1px solid rgba(22,163,74,.2);
}
.upload-result--warn {
  background: rgba(217,119,6,.06);
  border: 1px solid rgba(217,119,6,.2);
}
.upload-result h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: .75rem;
}
.upload-stats {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.upload-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.upload-stat__val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}
.upload-stat__label {
  font-size: .6875rem;
  color: var(--text-sub);
  margin-top: .2rem;
}
.upload-items-table {
  margin-top: .75rem;
  overflow-x: auto;
}
.upload-errors {
  margin-top: .75rem;
  padding: .75rem;
  background: rgba(220,38,38,.06);
  border: 1px solid rgba(220,38,38,.2);
  border-radius: var(--radius);
}
.upload-errors h5 {
  font-size: .8125rem;
  color: var(--danger);
  margin-bottom: .35rem;
}
.upload-errors ul {
  margin: 0;
  padding-left: 1.25rem;
  font-size: .8125rem;
  color: var(--danger);
}
.upload-errors li {
  padding: .1rem 0;
}

/* ─── Responsive (mobile) ─────────────────────────────────────── */
@media (max-width: 700px) {
  .sidebar { width: 50px; min-width: 50px; }
  .sidebar__brand, .sidebar__nav a span:last-child, .sidebar__footer span:first-child { display: none; }
  .sidebar__nav a { justify-content: center; padding: .75rem; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  input, select, textarea { max-width: 100%; }
  .item-detail__grid { grid-template-columns: 1fr; }
}
