:root {
  --color-navy: #1E293B;
  --color-slate: #334155;
  --color-bg: #F8FAFC;
  --color-accent: #D97706;
  --color-border: #E2E8F0;
  --color-text: #1E293B;
  --color-text-muted: #64748B;
  --color-danger: #DC2626;
  --color-white: #FFFFFF;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

a { color: var(--color-navy); }

.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--color-navy);
  color: var(--color-white);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
}
.btn:hover { background: var(--color-slate); }
.btn-accent { background: var(--color-accent); }
.btn-accent:hover { background: #B45309; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-size: 0.85rem; color: var(--color-text-muted); }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: 2px solid var(--color-accent); border-color: var(--color-accent); }
.field-error { display: block; margin-top: 0.25rem; font-size: 0.78rem; color: var(--color-danger); }

.alert {
  padding: 0.7rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error { background: #FEE2E2; color: var(--color-danger); border: 1px solid #FCA5A5; }
.alert-success { background: #DCFCE7; color: #166534; border: 1px solid #86EFAC; }

.card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.topbar {
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  padding: 0.85rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar a { color: var(--color-navy); text-decoration: none; }
.topbar .brand { font-weight: 600; letter-spacing: 0.02em; color: var(--color-navy); }

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 1.25rem; margin-bottom: 1.25rem; color: var(--color-navy); }

/* Admin shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex-shrink: 0; background: var(--color-navy); color: var(--color-white); overflow: hidden; }
.sidebar-brand {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  overflow: hidden;
}
.sidebar-logo {
  display: block;
  width: 140px;
  max-width: 100%;
  height: auto;
  background: var(--color-white);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
}
.sidebar-nav { list-style: none; margin: 0; padding: 0.75rem 0; }
.sidebar-nav li a {
  display: block;
  padding: 0.65rem 1.5rem;
  color: #CBD5E1;
  text-decoration: none;
  font-size: 0.9rem;
}
.sidebar-nav li a:hover { background: var(--color-slate); color: var(--color-white); }
.sidebar-nav li.active a { background: var(--color-accent); color: var(--color-white); font-weight: 600; }

.content-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
main { padding: 1.5rem; max-width: 1200px; width: 100%; }

.page-title { margin: 0; font-size: 1.15rem; color: var(--color-navy); }
.card-heading { margin: 0 0 0.85rem; font-size: 1rem; color: var(--color-navy); }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-value { font-size: 1.9rem; font-weight: 700; color: var(--color-navy); }
.stat-label { font-size: 0.85rem; color: var(--color-text-muted); margin-top: 0.25rem; }
.stat-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 10px;
  padding: 0.6rem;
  margin: -0.6rem;
  transition: background 0.15s ease;
}
.stat-card-link:hover { background: var(--color-bg); }

/* Dashboard widgets */
.dashboard-hint { color: var(--color-text-muted); font-size: 0.82rem; margin: -0.5rem 0 1rem; }
.dashboard-widget {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-bottom: 1.5rem;
  transition: opacity 0.15s ease;
}
.dashboard-widget.dragging { opacity: 0.4; }
.widget-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.widget-handle { cursor: grab; color: var(--color-text-muted); font-size: 1rem; line-height: 1; }
.widget-handle:active { cursor: grabbing; }
.widget-title { font-weight: 600; color: var(--color-navy); font-size: 1rem; flex: 1; }
.widget-move-buttons { display: flex; gap: 0.25rem; }
.widget-move-buttons button {
  border: 1px solid var(--color-border);
  background: var(--color-white);
  border-radius: 5px;
  width: 1.6rem;
  height: 1.6rem;
  font-size: 0.7rem;
  color: var(--color-slate);
  cursor: pointer;
}
.widget-move-buttons button:hover:not(:disabled) { background: var(--color-bg); }
.widget-move-buttons button:disabled { opacity: 0.35; cursor: default; }
.widget-body { padding: 1.25rem; }

.filter-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FDE68A;
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.filter-chip a { color: #92400E; font-weight: 600; text-decoration: underline; }

/* Job order activity feed */
.activity-feed { margin-top: 1.25rem; border-top: 1px solid var(--color-border); padding-top: 1rem; }
.activity-entry { padding: 0.75rem 0; border-bottom: 1px solid var(--color-border); }
.activity-entry:last-child { border-bottom: none; }
.activity-meta { display: flex; align-items: baseline; gap: 0.5rem; font-size: 0.85rem; }
.activity-time { color: var(--color-text-muted); font-size: 0.78rem; }
.activity-tag {
  display: inline-block;
  margin-top: 0.35rem;
  margin-right: 0.4rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: #FEF3C7;
  color: #92400E;
  font-size: 0.72rem;
  font-weight: 600;
}
.activity-text { margin: 0.4rem 0 0; font-size: 0.9rem; white-space: pre-wrap; }

/* Stage bar list */
.stage-bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
  font-size: 0.85rem;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  margin-left: -0.4rem;
  margin-right: -0.4rem;
  transition: background 0.15s ease;
}
.stage-bar-row:hover { background: var(--color-bg); }
.stage-bar-label { width: 280px; flex-shrink: 0; }
.stage-bar-track { flex: 1; background: #EEF2F7; border-radius: 4px; height: 10px; overflow: hidden; }
.stage-bar-fill { background: var(--color-accent); height: 100%; }
.stage-bar-count { width: 2rem; text-align: right; font-weight: 600; }

.chart-bar-link { cursor: pointer; }
.chart-bar-link rect:first-child { transition: fill 0.15s ease; }
.chart-bar-link:hover rect:first-child { fill: #B45309; }

/* Data tables */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--color-border); text-align: left; font-size: 0.9rem; white-space: nowrap; }
.table th { background: #F1F5F9; font-weight: 600; color: var(--color-slate); }
.row-actions { display: flex; gap: 0.4rem; align-items: center; }
.row-actions form { margin: 0; }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-active { background: #DCFCE7; color: #166534; }
.badge-inactive { background: #FEE2E2; color: #991B1B; }
.badge-warn { background: #FEF3C7; color: #92400E; }

/* Dashboard chart */
.chart-svg { width: 100%; max-width: 640px; height: auto; }

/* Toolbar (search + primary action above a data table) */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }
.toolbar form { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.toolbar input[type="text"] { padding: 0.5rem 0.75rem; border: 1px solid var(--color-border); border-radius: 6px; min-width: 240px; }

/* Buttons */
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-outline { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: #F1F5F9; }
.btn-danger { background: var(--color-danger); }
.btn-danger:hover { background: #B91C1C; }

/* Pagination */
.pagination { display: flex; gap: 0.35rem; margin-top: 1rem; }
.pagination a { padding: 0.35rem 0.65rem; border: 1px solid var(--color-border); border-radius: 5px; font-size: 0.85rem; text-decoration: none; color: var(--color-text); }
.pagination a.active { background: var(--color-navy); color: var(--color-white); border-color: var(--color-navy); }

/* Forms */
.form-card { max-width: 520px; }
.form-card-wide { max-width: 900px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1rem; }
.customer-info-box { margin-top: 0.5rem; font-size: 0.82rem; color: var(--color-text-muted); line-height: 1.5; }

/* Quotation line-item table */
.item-table th, .item-table td { white-space: normal; vertical-align: top; }
.item-table .catalog-picker { width: 100%; margin-bottom: 0.3rem; font-size: 0.82rem; padding: 0.3rem; border: 1px solid var(--color-border); border-radius: 4px; }
.item-table input, .item-table textarea { width: 100%; padding: 0.4rem; border: 1px solid var(--color-border); border-radius: 4px; font-size: 0.85rem; font-family: inherit; }
.item-table .item-qty, .item-table .item-unit-price { min-width: 5.5rem; }
.item-table .item-amount { font-weight: 600; text-align: right; white-space: nowrap; }
.grand-total { margin: 0.75rem 0 1.5rem; text-align: right; font-size: 1.1rem; font-weight: 700; color: var(--color-navy); }
.perm-group { margin-bottom: 1.25rem; }
.perm-group h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); margin: 0 0 0.5rem; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.4rem; }
.perm-check { font-size: 0.85rem; display: flex; gap: 0.4rem; align-items: center; font-weight: 400; }

@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .sidebar-nav { display: flex; flex-wrap: wrap; padding: 0.5rem; gap: 0.25rem; }
  .sidebar-nav li a { padding: 0.5rem 0.85rem; border-radius: 6px; }
  .stage-bar-label { width: 160px; font-size: 0.78rem; }
}
