/* ── Inter font ────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

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

:root {
  --sidebar-w:    240px;
  --topbar-h:     56px;

  --color-bg:     #f8fafc;
  --color-card:   #ffffff;
  --color-border: #e8edf2;
  --color-text:   #0f172a;
  --color-muted:  #64748b;
  --color-primary:#3b82f6;
  --color-primary-dark: #2563eb;

  --sidebar-bg:   #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active-bg:  #1e293b;
  --sidebar-active-txt: #f8fafc;

  --radius:  6px;
  --shadow:  0 1px 2px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.06);
}

html { font-size: 14px; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

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

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

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform .25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--topbar-h);
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #f8fafc;
  font-weight: 700;
  font-size: .95rem;
  text-decoration: none;
}
.logo-icon { font-size: 1.2rem; }

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.nav-item:hover, .nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-txt);
  text-decoration: none;
  border-left-color: var(--color-primary);
}
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: .6; }
.nav-divider { height: 1px; background: rgba(255,255,255,.07); margin: 8px 0; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.user-info { flex: 1; min-width: 0; }
.user-name  { color: #f8fafc; font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { color: var(--sidebar-text); font-size: .75rem; }
.btn-logout {
  color: var(--sidebar-text);
  font-size: 1.1rem;
  flex-shrink: 0;
  padding: 4px;
  text-decoration: none;
}
.btn-logout:hover { color: #f87171; text-decoration: none; }

/* ── Main area ─────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--color-muted);
  padding: 4px 8px;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

.content {
  flex: 1;
  padding: 28px 28px;
  max-width: 1280px;
  width: 100%;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text);
}
.card-body { padding: 20px; }
.card-body + .card-body { border-top: 1px solid var(--color-border); }

/* ── Stat cards ────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: .78rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--color-text); margin-top: 4px; }
.stat-sub   { font-size: .78rem; color: var(--color-muted); margin-top: 2px; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table th {
  background: #f8fafc;
  text-align: left;
  padding: 9px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table td.actions { white-space: nowrap; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s;
  line-height: 1;
}
.btn:hover { opacity: .85; text-decoration: none; }

.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--color-text); }
.btn-success   { background: #16a34a; color: #fff; }
.btn-danger    { background: #dc2626; color: #fff; }
.btn-warning   { background: #d97706; color: #fff; }
.btn-sm        { padding: 4px 10px; font-size: .8rem; }
.btn-ghost     { background: transparent; color: var(--color-primary); border: 1px solid var(--color-border); }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  line-height: 1.6;
}

/* production statuses */
.badge-order                  { background: #f1f5f9; color: #475569; }
.badge-respo-production       { background: #dbeafe; color: #1d4ed8; }
.badge-respo-ready            { background: #e0f2fe; color: #0369a1; }
.badge-delivery-inbound       { background: #fef3c7; color: #92400e; }
.badge-thors-haven-production { background: #ede9fe; color: #6d28d9; }
.badge-finished               { background: #ccfbf1; color: #0f766e; }
.badge-delivered              { background: #dcfce7; color: #15803d; }
.badge-deployed               { background: #166534; color: #f0fdf4; }

/* sales statuses */
.badge-contract { background: #fef9c3; color: #854d0e; }
.badge-paid     { background: #dcfce7; color: #15803d; }

/* payment statuses */
.badge-pending  { background: #f1f5f9; color: #475569; }
.badge-invoiced { background: #dbeafe; color: #1d4ed8; }
.badge-partial  { background: #fef3c7; color: #92400e; }
/* .badge-paid — reused from sales */

/* component statuses */
.badge-ordered   { background: #dbeafe; color: #1d4ed8; }
.badge-received  { background: #fef3c7; color: #92400e; }
.badge-installed { background: #dcfce7; color: #15803d; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid.col-1 { grid-template-columns: 1fr; }
.form-grid.col-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }

label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

input[type=text], input[type=email], input[type=password],
input[type=date], input[type=number], input[type=tel],
select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 400;
  color: var(--color-text);
  background: #fff;
  transition: border-color .15s;
  font-family: inherit;
  line-height: 1.5;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
textarea { resize: vertical; min-height: 80px; }
select   { cursor: pointer; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.field-hint { font-size: .78rem; color: var(--color-muted); margin-top: 2px; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 20px;
  border-left: 4px solid;
}
.alert-success { background: #f0fdf4; border-color: #16a34a; color: #15803d; }
.alert-error, .alert-danger { background: #fef2f2; border-color: #dc2626; color: #b91c1c; }
.alert-warning  { background: #fffbeb; border-color: #d97706; color: #92400e; }
.alert-info     { background: #eff6ff; border-color: #3b82f6; color: #1d4ed8; }

/* ── Page header row ───────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h2 { font-size: 1.15rem; font-weight: 700; }

/* ── Filter bar ────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-bar input, .filter-bar select {
  width: auto;
  min-width: 140px;
}

/* ── Order view detail grid ────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 20px;
  font-size: .9rem;
}
.detail-row { display: contents; }
.detail-label { color: var(--color-muted); font-size: .8rem; padding: 5px 0; }
.detail-value { padding: 5px 0; font-weight: 500; }

/* ── Status selector (inline form) ────────────────────────────────────────── */
.status-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.status-form select {
  width: auto;
  min-width: 180px;
}

/* ── Timeline / log ────────────────────────────────────────────────────────── */
.timeline { list-style: none; padding: 0; }
.timeline li {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: .875rem;
}
.timeline li:last-child { border-bottom: none; }
.tl-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  flex-shrink: 0;
  margin-top: 6px;
}
.tl-time { color: var(--color-muted); font-size: .78rem; white-space: nowrap; }
.tl-body { flex: 1; }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-muted);
}
.empty-state .empty-icon { margin-bottom: 12px; color: #cbd5e1; }
.empty-state p { font-size: .9rem; margin-bottom: 16px; }

/* ── Login page ────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 24px;
}
.login-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo h1 { font-size: 1.2rem; color: var(--color-text); margin-top: 8px; }
.login-logo .logo-anchor { font-size: 2rem; }
.login-card .form-group { margin-bottom: 14px; }
.login-card label { margin-bottom: 5px; display: block; }
.btn-login {
  width: 100%;
  padding: 10px;
  margin-top: 6px;
  justify-content: center;
}

/* ── Pagination ────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 16px;
  font-size: .85rem;
}
.page-link {
  padding: 5px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-primary);
  background: #fff;
}
.page-link.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.page-link:hover { text-decoration: none; opacity: .85; }

/* ── Page layout grids ─────────────────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.sidebar-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .dashboard-grid,
  .two-col-grid,
  .sidebar-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.text-muted  { color: var(--color-muted); }
.text-sm     { font-size: .8rem; }
.text-right  { text-align: right; }
.mt-4        { margin-top: 16px; }
.mt-6        { margin-top: 24px; }
.mb-4        { margin-bottom: 16px; }
.flex        { display: flex; }
.gap-2       { gap: 8px; }
.items-center{ align-items: center; }

/* ── Sidebar overlay (mobile) ──────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .sidebar-close  { display: block; }
  .sidebar-overlay.open { display: block; }
  .main           { margin-left: 0; }
  .topbar-toggle  { display: block; }

  .form-grid        { grid-template-columns: 1fr; }
  .form-group.span-2,
  .form-group.span-3 { grid-column: span 1; }

  .stats-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid{ grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .content     { padding: 14px; }
  .stats-grid  { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .filter-bar  { flex-direction: column; }
  .filter-bar input, .filter-bar select { width: 100%; min-width: unset; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-label { padding-bottom: 0; }
  .detail-value { padding-top: 1px; padding-bottom: 10px; }
}
