:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eaf1ff;
  --text: #0f172a;
  --text-muted: #64748b;
  --danger: #dc2626;
  --danger-soft: #fdeaea;
  --success: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }

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

a { color: inherit; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

/* ---------------------------------------------------------------- layout */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.brand-name {
  font-weight: 800;
  font-size: 18px;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.brand-company {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-tabs a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13.5px;
}

.nav-tabs a:hover { background: var(--bg); color: var(--text); }
.nav-tabs a.is-active { background: var(--primary-soft); color: var(--primary); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

.logout-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
}
.logout-btn:hover { background: var(--bg); color: var(--text); }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 36px 60px;
}

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

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

.panel-head h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.panel-head p {
  margin: 0;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.card h2, .card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-tile .num {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
}

.stat-tile .label {
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  text-decoration: none;
}

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

.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--bg); }

.btn--danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn--danger:hover { background: #fadada; }

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

.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------------- forms */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field span.label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.field input[type="text"],
.field input[type="password"],
.field input[type="tel"],
.field textarea,
.field select {
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  width: 100%;
}

.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; flex: 1; min-width: 160px; }

/* ---------------------------------------------------------------- lists */

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.item-row:last-child { border-bottom: none; }

.item-row .item-main { flex: 1; min-width: 0; }
.item-row .item-title { font-weight: 700; }
.item-row .item-sub { color: var(--text-muted); font-size: 12.5px; }
.item-row.is-hidden { opacity: .5; }

.item-actions { display: flex; gap: 6px; flex-shrink: 0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge--muted { background: var(--bg); color: var(--text-muted); }
.badge--new { background: #fef3c7; color: #92400e; }
.badge--done { background: #dcfce7; color: #166534; }

.category-block { margin-bottom: 18px; }
.category-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.category-head h3 { margin: 0; }

.toggle {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.toggle .track {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background .15s;
}
.toggle .thumb {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
  transition: transform .15s;
}
.toggle input:checked + .track { background: var(--primary); }
.toggle input:checked + .track + .thumb { transform: translateX(16px); }

.gallery-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.gallery-thumb {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.gallery-thumb img { width: 100%; height: 100px; object-fit: cover; display: block; }
.gallery-thumb .thumb-body { padding: 8px; }
.gallery-thumb .thumb-caption { font-size: 12px; margin-bottom: 6px; word-break: break-word; }
.gallery-thumb.is-hidden { opacity: .5; }
.gallery-thumb .thumb-actions { display: flex; gap: 4px; }

.empty-state {
  color: var(--text-muted);
  padding: 24px 8px;
  text-align: center;
}

.history-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.history-entry:last-child { border-bottom: none; }
.history-entry .desc { font-weight: 600; }
.history-entry .meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th, table.data-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
table.data-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

.hint { color: var(--text-muted); font-size: 12.5px; margin-top: -6px; margin-bottom: 12px; }

/* ---------------------------------------------------------------- toast */

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 320px;
}
.toast.is-error { background: var(--danger); }

/* ---------------------------------------------------------------- confirm dialog */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.dialog-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 320px;
  box-shadow: var(--shadow);
}
.dialog-box h3 { margin: 0 0 8px; font-size: 15px; }
.dialog-box p { margin: 0 0 16px; color: var(--text-muted); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------------------------------------------------------- login page */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eef3ff 0%, var(--bg) 60%);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 360px;
}
.login-card .brand-block { border: none; padding: 0 0 22px; margin-bottom: 4px; }
.login-card .brand-name { font-size: 22px; }
.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute;
  left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 180px;
  overflow-y: auto;
  z-index: 10;
}
.autocomplete-list button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border: none;
  background: none;
  cursor: pointer;
}
.autocomplete-list button:hover { background: var(--primary-soft); }
.login-error { color: var(--danger); font-size: 13px; margin: 8px 0 0; min-height: 18px; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; bottom: 0; top: auto; width: 100%; height: auto; flex-direction: row; overflow-x: auto; padding: 8px; z-index: 50; }
  .sidebar .brand-block, .sidebar-footer { display: none; }
  .nav-tabs { flex-direction: row; }
  .nav-tabs a { white-space: nowrap; }
  .main { padding: 20px 16px 90px; }
}
