:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --card-soft: #f8fafc;
  --line: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --accent: #4f97b7;
  --accent-dark: #3f7f9d;
  --accent-soft: #eff8fc;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --ok: #166534;
  --ok-soft: #f0fdf4;
  --warn: #92400e;
  --warn-soft: #fffbeb;
  --info-soft: #eff6ff;
  --shadow: 0 4px 16px rgba(17,24,39,.07);
  --radius: 14px;
  --sidebar-w: 230px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────── */
#app { display: none; }
#app.ready { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: #1e2a38;
  color: #d1d5db;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-logo {
  padding: 20px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo img {
  width: 100%;
  max-width: 160px;
  filter: brightness(0) invert(1);
  opacity: .85;
}
.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6b7280;
  padding: 18px 18px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 8px;
  margin: 1px 8px;
  cursor: pointer;
  color: #9ca3af;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
  border: none;
  background: none;
  width: calc(100% - 16px);
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #e5e7eb; }
.nav-item.active { background: rgba(79,151,183,.2); color: #7fc8e2; }
.nav-icon { width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-spacer { flex: 1; }
.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 13px;
  color: #9ca3af;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
#logout-btn {
  font-size: 12px;
  background: rgba(185,28,28,.3);
  color: #fca5a5;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-weight: 700;
}
#logout-btn:hover { background: rgba(185,28,28,.5); }

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.topbar-title {
  font-size: 17px;
  font-weight: 700;
}
.page-content {
  padding: 28px;
  flex: 1;
}

/* ── Login ───────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}
.login-logo { margin-bottom: 24px; text-align: center; }
.login-logo img { width: 160px; height: auto; }
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 20px; text-align: center; }

/* ── Cards / containers ──────────────────────── */
.card {
  background: var(--card);
  border: 1px solid rgba(209,213,219,.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card.flush { padding: 0; }
.stack { display: grid; gap: 18px; }
.stack-sm { display: grid; gap: 10px; }

/* ── Forms ───────────────────────────────────── */
label {
  display: block;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 5px;
  color: #374151;
}
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #9ca3af;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(79,151,183,.25);
  border-color: var(--accent);
}
textarea { min-height: 90px; resize: vertical; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.full { grid-column: 1/-1; }

/* ── Buttons ─────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .btn:hover { background: var(--accent-dark); }
button.secondary, .btn.secondary { background: #374151; }
button.secondary:hover, .btn.secondary:hover { background: #1f2937; }
button.danger, .btn.danger { background: var(--danger); }
button.danger:hover, .btn.danger:hover { background: #991b1b; }
button.ghost, .btn.ghost {
  background: none;
  color: var(--accent-dark);
  border: 1px solid var(--accent);
}
button.ghost:hover, .btn.ghost:hover { background: var(--accent-soft); }
button.sm { min-height: 32px; padding: 5px 12px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; }
.actions.between { justify-content: space-between; }

/* ── Tables ──────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  text-align: left;
  padding: 10px 14px;
  background: #f9fafb;
  border-bottom: 2px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f3f5;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--accent-soft); }
.data-table .row-link { cursor: pointer; }

/* ── Badges ──────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-request    { background: #fef3c7; color: #92400e; }
.badge-released   { background: #dbeafe; color: #1e40af; }
.badge-completed  { background: #d1fae5; color: #065f46; }
.badge-quote      { background: #ede9fe; color: #5b21b6; }
.badge-accepted   { background: #dcfce7; color: var(--ok); }
.badge-rejected   { background: #fee2e2; color: var(--danger); }
.badge-cancelled  { background: #f3f4f6; color: #374151; }
.badge-done       { background: #1e2a38; color: #d1d5db; }
.badge-active     { background: #d1fae5; color: var(--ok); }
.badge-inactive   { background: #f3f4f6; color: #374151; }

/* ── Notices ─────────────────────────────────── */
.notice {
  border-radius: 10px;
  padding: 12px 15px;
  border: 1px solid transparent;
  font-size: 14px;
}
.notice.ok   { background: var(--ok-soft);    border-color: #bbf7d0; color: var(--ok); }
.notice.warn { background: var(--warn-soft);   border-color: #fde68a; color: var(--warn); }
.notice.err  { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.notice.info { background: var(--info-soft);   border-color: #bfdbfe; }

/* ── Status message bar ──────────────────────── */
.status-bar {
  min-height: 20px;
  font-size: 14px;
  font-weight: 700;
}
.status-bar.ok  { color: var(--ok); }
.status-bar.err { color: var(--danger); }

/* ── Detail sections ─────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.detail-field label { color: var(--muted); font-weight: 400; font-size: 12px; margin-bottom: 2px; }
.detail-field p { font-weight: 700; font-size: 15px; }

.history-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid #f1f3f5;
  font-size: 13px;
}
.history-row:last-child { border-bottom: none; }
.history-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 4px;
  flex-shrink: 0;
}

/* ── Price rows ──────────────────────────────── */
.price-row {
  display: grid;
  grid-template-columns: 1fr 120px 120px 120px;
  gap: 10px;
  align-items: end;
  padding: 12px 0;
  border-bottom: 1px solid #f1f3f5;
}
.price-row:last-child { border-bottom: none; }
.price-row-name { font-weight: 700; font-size: 14px; }
.price-row-qty  { font-size: 13px; color: var(--muted); }
@media (max-width: 700px) {
  .price-row { grid-template-columns: 1fr 1fr; }
}

/* ── Totals ──────────────────────────────────── */
.total-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid #f1f3f5;
  font-size: 14px;
}
.total-line:last-child { border-bottom: none; }
.total-line.big { font-weight: 700; font-size: 17px; }

/* ── Misc ────────────────────────────────────── */
.muted { color: var(--muted); }
.small { font-size: 13px; color: var(--muted); }
.text-right { text-align: right; }
.divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.loading { color: var(--muted); padding: 32px; text-align: center; font-size: 14px; }
.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 14px;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-header h2 { font-size: 20px; }
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filters select, .filters input { width: auto; min-width: 140px; }
.toggle-active {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
.toggle-active input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .page-content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .price-row { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
}
