:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */
.topbar {
  background: #0f172a;
  color: #e2e8f0;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.topbar .brand {
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 16px;
  color: #fff;
  white-space: nowrap;
}

.topbar .brand span { color: #60a5fa; }

.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }

.topbar nav a {
  color: #cbd5e1;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 500;
}

.topbar nav a:hover { background: #1e293b; text-decoration: none; color: #fff; }
.topbar nav a.active { background: #1d4ed8; color: #fff; }

.container { max-width: 1240px; margin: 0 auto; padding: 24px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-head h1 { font-size: 22px; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--muted); }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

.card h2 { font-size: 15px; margin: 0 0 14px; }
.card h2 small { font-weight: 400; color: var(--muted); margin-left: 6px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

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

table { width: 100%; border-collapse: collapse; min-width: 640px; }

th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }

th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); background: #f9fafb; }

tbody tr:hover { background: #f9fafb; }
tbody tr:last-child td { border-bottom: none; }

td .sub { display: block; color: var(--muted); font-size: 12px; }
td.num, th.num { text-align: right; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.gray { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.badge.blue { background: #e0edff; color: #1d4ed8; border-color: #bfdbfe; }
.badge.green { background: #dcfce7; color: #047857; border-color: #bbf7d0; }
.badge.amber { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.badge.red { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.badge.violet { background: #ede9fe; color: #6d28d9; border-color: #ddd6fe; }


/* ---------- forms ---------- */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 14px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.field.grow { flex: 1 1 220px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  width: 100%;
}

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

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

.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox input { width: 16px; height: 16px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

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

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

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 760px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #f9fafb;
  border-radius: 0 0 14px 14px;
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
}

.icon-btn:hover { background: #f1f5f9; color: var(--text); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.2s ease;
  z-index: 80;
  max-width: 380px;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #991b1b; }
.toast.success { background: #065f46; }

/* ---------- misc ---------- */
.stack { display: flex; flex-direction: column; gap: 6px; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.right { text-align: right; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px; }
.detail-grid div span { display: block; font-size: 12px; color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); position: absolute; left: -5px; top: 14px; }
.timeline .when { color: var(--muted); font-size: 12px; }

@media (max-width: 640px) {
  .container { padding: 16px; }
  .topbar { height: auto; padding: 10px 16px; gap: 10px; }
}

/* ---------- signed-in user ---------- */
.topbar .spacer { flex: 1 1 auto; }

.topbar .session {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cbd5e1;
  font-size: 13px;
}

.topbar .session strong { color: #fff; font-weight: 600; }

.topbar .session button {
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  padding: 5px 10px;
  font-size: 12px;
}

.topbar .session button:hover { background: #334155; }

/* ---------- login screen ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at 20% 20%, #1e293b 0%, #0f172a 45%, #020617 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 16px;
  padding: 30px 28px 24px;
  box-shadow: 0 30px 70px rgba(2, 6, 23, 0.55);
}

.login-brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
  color: #0f172a;
  margin-bottom: 14px;
}

.login-brand span { color: var(--primary); }

.login-card h1 { font-size: 21px; margin: 0 0 4px; }
.login-card > p { margin: 0 0 18px; font-size: 13px; }

.login-form { display: flex; flex-direction: column; gap: 14px; }

.login-submit { width: 100%; justify-content: center; padding: 10px 14px; }

.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
}

.login-error[hidden] { display: none; }

.login-foot {
  margin: 18px 0 0;
  font-size: 11.5px;
  text-align: center;
  line-height: 1.6;
}

.login-foot code {
  background: #f1f5f9;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 11px;
}

/* ---------- devices / shop ---------- */
.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.unit-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.unit-card .photo { aspect-ratio: 4 / 3; background: #f1f5f9; }
.unit-card .photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

.unit-card .no-photo {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}

.unit-card .thumbs {
  display: flex;
  gap: 6px;
  padding: 8px 10px 0;
  min-height: 6px;
}

.unit-card .thumbs img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.unit-card .thumbs img:hover { border-color: var(--primary); }

.unit-card .body {
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.unit-card h3 { margin: 0; font-size: 15px; }
.unit-card .price { font-size: 18px; font-weight: 700; margin-top: auto; }
.unit-card .meta { display: flex; gap: 6px; flex-wrap: wrap; }

.thumb-sm {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8fafc;
  display: block;
}

.photo-slots { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.photo-slot {
  width: 84px;
  height: 84px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }

.photo-slot .del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

input[type="file"] { padding: 6px; background: #fff; }

/* clickable "add photo" slot */
.photo-slot.add {
  border: 1px dashed #94a3b8;
  background: #f8fafc;
  color: var(--primary);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  padding: 6px;
  line-height: 1.3;
}

.photo-slot.add:hover {
  background: #eff6ff;
  border-color: var(--primary);
}

.photo-slot .cover-tag {
  position: absolute;
  left: 3px;
  bottom: 3px;
  background: rgba(37, 99, 235, 0.85);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3px;
  border-radius: 4px;
  padding: 1px 4px;
  text-transform: uppercase;
}
