:root {
  --ink: #17211f;
  --ink-muted: #5c6d69;
  --ink-faint: #8a9894;
  --bg: #eef2f0;
  --surface: #ffffff;
  --surface-alt: #f4f7f6;
  --border: #dbe4e1;
  --border-strong: #c3d0cc;

  --accent: #1f6f6b;
  --accent-dark: #144e4a;
  --accent-soft: #e2f1ef;
  --accent-ink: #ffffff;

  --danger: #b0402f;
  --danger-bg: #fbe9e6;
  --success: #2c7a4b;
  --success-bg: #e4f3e9;
  --warning: #9a6400;
  --warning-bg: #fbf1dd;
  --info: #2a5f96;
  --info-bg: #e6eef8;

  --radius: 8px;
  --radius-sm: 5px;
  --shadow-sm: 0 1px 2px rgba(23, 33, 31, 0.06);
  --shadow-md: 0 4px 14px rgba(23, 33, 31, 0.08);
  --sidebar-w: 236px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

.container { max-width: 880px; margin: 0 auto; padding: 2.25rem 1.25rem; }
.container-wide { max-width: 1220px; margin: 0 auto; padding: 1.75rem 1.75rem 3rem; width: 100%; }

/* ---------- App shell: sidebar + content ---------- */

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

.sidebar {
  width: var(--sidebar-w); flex: none; min-height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 1.35rem 1.25rem 1.1rem; border-bottom: 1px solid var(--border);
}
.brand-mark {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: var(--accent-ink); font-weight: 700; font-size: 1.05rem;
}
.brand-text { font-weight: 700; font-size: 0.95rem; line-height: 1.25; }

.sidebar-nav { flex: 1; padding: 0.9rem 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; overflow-y: auto; }
.sidebar-nav a {
  display: block; padding: 0.55rem 0.75rem; border-radius: var(--radius-sm);
  color: var(--ink); text-decoration: none; font-size: 0.92rem; font-weight: 500;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: var(--surface-alt); color: var(--ink); }
.sidebar-nav a.active { background: var(--accent-soft); color: var(--accent-dark); border-left-color: var(--accent); font-weight: 600; }
.sidebar-section {
  margin: 0.9rem 0 0.15rem; padding: 0 0.75rem; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint);
}

.sidebar-footer { padding: 0.9rem; border-top: 1px solid var(--border); }
.user-chip { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.7rem; }
.user-chip .user-name { font-weight: 600; font-size: 0.9rem; }

.main-area { flex: 1; min-width: 0; }

/* ---------- Cards, headings ---------- */

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

h1 { font-size: 1.55rem; margin: 0 0 1.15rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 0.9rem; letter-spacing: -0.005em; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; color: var(--ink); }
code { font-family: var(--font-mono); font-size: 0.85em; background: var(--surface-alt); padding: 0.1em 0.4em; border-radius: 4px; }

/* ---------- Stat cards (dashboards) ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm);
}
.stat-card .stat-label { font-size: 0.78rem; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.stat-card .stat-value { font-size: 1.85rem; font-weight: 700; margin-top: 0.3rem; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-card .stat-meta { font-size: 0.82rem; color: var(--ink-muted); margin-top: 0.35rem; }

/* ---------- Forms ---------- */

.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.85rem; color: var(--ink); }
.field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=number], .field input[type=url], .field input[type=date],
.field input[type=datetime-local], .field select, .field textarea {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 0.92rem; background: var(--surface); color: var(--ink); font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 160px; }
.hint { color: var(--ink-muted); font-size: 0.84rem; margin-top: 0.25rem; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.58rem 1.05rem; border-radius: var(--radius-sm);
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font-size: 0.9rem; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}
.btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: var(--accent-ink); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-alt); border-color: var(--ink-faint); color: var(--ink); }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Alerts ---------- */

.alert { padding: 0.8rem 1.05rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem; font-size: 0.9rem; border: 1px solid transparent; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(176, 64, 47, 0.18); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(44, 122, 75, 0.18); }

.check-list { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.check-list li { padding: 0.3rem 0; display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.9rem; }
.check-list .ok { color: var(--success); font-weight: 700; }
.check-list .fail { color: var(--danger); font-weight: 700; }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.65rem; border-bottom: 1px solid var(--border); font-size: 0.89rem; }
th { color: var(--ink-muted); font-weight: 600; text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.04em; }
tbody tr:hover { background: var(--surface-alt); }

/* ---------- Badges (status-aware) ---------- */

.badge {
  display: inline-block; padding: 0.2rem 0.55rem; border-radius: 99px; font-size: 0.74rem; font-weight: 600;
  background: var(--border); color: var(--ink-muted); letter-spacing: 0.01em;
}
.badge-accent { background: var(--accent-soft); color: var(--accent-dark); }
.badge-open, .badge-submitted, .badge-new { background: var(--info-bg); color: var(--info); }
.badge-collecting, .badge-purchasing, .badge-draft, .badge-in_progress { background: var(--warning-bg); color: var(--warning); }
.badge-shipped, .badge-ordered, .badge-approved, .badge-resolved, .badge-applied, .badge-received { background: var(--success-bg); color: var(--success); }
.badge-closed { background: var(--border); color: var(--ink-muted); }
.badge-cancelled, .badge-rejected, .badge-problem { background: var(--danger-bg); color: var(--danger); }

/* ---------- Greeting banner ---------- */

.greeting-banner {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: var(--accent-ink); border-radius: var(--radius); padding: 1.5rem 1.75rem; margin-bottom: 1.35rem;
  box-shadow: var(--shadow-md);
}
.greeting-banner h1 { color: var(--accent-ink); margin: 0 0 0.35rem; }
.greeting-banner p { margin: 0; opacity: 0.92; font-size: 0.95rem; }

/* ---------- Auth / install shell (login, installer) ---------- */

.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; }
.auth-shell .container { padding: 0; width: 100%; max-width: 420px; }
.auth-shell h1 { text-align: center; font-size: 1.3rem; margin-bottom: 1.5rem; }
.install-shell .container { max-width: 620px; }

/* ---------- Responsive: collapse sidebar to a top bar ---------- */

@media (max-width: 880px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; min-height: 0; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar-brand { border-bottom: none; border-right: 1px solid var(--border); padding: 0.75rem 1rem; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; padding: 0.5rem 0.75rem; overflow-x: auto; }
  .sidebar-nav a { border-left: none; border-bottom: 2px solid transparent; padding: 0.45rem 0.6rem; white-space: nowrap; }
  .sidebar-nav a.active { border-left-color: transparent; border-bottom-color: var(--accent); }
  .sidebar-section { display: none; }
  .sidebar-footer { border-top: none; border-left: 1px solid var(--border); display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 1rem; }
  .user-chip { flex-direction: row; align-items: center; gap: 0.5rem; margin-bottom: 0; }
  .container-wide { padding: 1.25rem 1rem 2.5rem; }
}

@media print {
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}
