:root {
  --bg: #0f1419;
  --panel: #1a1f27;
  --line: #2d3339;
  --text: #e4e6eb;
  --muted: #9ca3af;
  --brand: #3b82f6;
  --brand-2: #1e40af;
  --accent: #8b5cf6;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Manrope",
    "Avenir Next",
    "Segoe UI",
    sans-serif;
}

/* ── App shell ──────────────────────────────────────────────────────────── */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-y: auto;
}

.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: 0.06em;
  color: var(--brand);
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ── Navigation ─────────────────────────────────────────────────────────── */

.nav {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  border-radius: 10px;
  color: var(--text);
  transition: background 140ms ease;
  font-size: 0.9rem;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
}

.nav-link.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--brand);
  font-weight: 700;
}

.nav-group {
  margin-top: 4px;
}

.group-trigger {
  width: 100%;
  border: 0;
  color: var(--muted);
  background: transparent;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: left;
  cursor: default;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.subnav {
  padding-left: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Main panel ─────────────────────────────────────────────────────────── */

.main-panel {
  padding: 28px;
  overflow-y: auto;
  max-height: 100vh;
}

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

.main-header h2 {
  margin: 0;
  font-size: 1.6rem;
}

.main-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

/* ── Toolbar ────────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.toolbar-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toolbar-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toolbar-block-title {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.toolbar-block-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ── Content area ───────────────────────────────────────────────────────── */

.content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  min-height: 200px;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */

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

.input,
.select {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 9px 12px;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.select {
  min-width: 86px;
}

textarea.input {
  resize: vertical;
  min-height: 80px;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  transition: background 140ms ease;
}

.btn:hover {
  background: var(--brand-2);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.btn.secondary:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn.danger {
  background: var(--danger);
}

.btn.danger:hover {
  background: #dc2626;
}

.btn.success {
  background: var(--success);
  color: #000;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-sm {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
}

a.btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

tbody tr:nth-child(even):hover {
  background: rgba(255, 255, 255, 0.04);
}

.table-action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Status badges ──────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge.draft {
  background: rgba(156, 163, 175, 0.2);
  color: var(--muted);
}

.badge.submitted {
  background: rgba(59, 130, 246, 0.2);
  color: var(--brand);
}

.badge.confirmed {
  background: rgba(139, 92, 246, 0.2);
  color: var(--accent);
}

.badge.acknowledged {
  background: rgba(139, 92, 246, 0.2);
  color: var(--accent);
}

.badge.partially_shipped {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.badge.shipped {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
}

.badge.received {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.badge.partial,
.badge.partially_received {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.badge.cancelled {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

/* ── Cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.stat-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--brand);
}

.stat-card .stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 800;
}

/* ── Status cards (feedback) ────────────────────────────────────────────── */

.status {
  padding: 14px 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
}

.status.ok,
.status.success {
  background: rgba(34, 197, 94, 0.12);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.status.error {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.status.warning {
  background: rgba(245, 158, 11, 0.12);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.status.info {
  background: rgba(59, 130, 246, 0.12);
  color: var(--brand);
  border: 1px solid rgba(59, 130, 246, 0.25);
}

/* ── Modal overlay ──────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.4rem;
  padding: 4px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ── File drop zone ─────────────────────────────────────────────────────── */

.drop-zone {
  border: 2px dashed var(--line);
  border-radius: 14px;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 200ms ease, background 200ms ease;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--brand);
  background: rgba(59, 130, 246, 0.06);
}

.drop-zone p {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.drop-zone .hint {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Pagination ─────────────────────────────────────────────────────────── */

.pager-indicator {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  padding: 0 4px;
}

/* ── Loading ────────────────────────────────────────────────────────────── */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
  font-size: 0.95rem;
}

.loading::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  margin-right: 10px;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Empty state ────────────────────────────────────────────────────────── */

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

.empty-state p {
  margin: 8px 0 0;
  font-size: 0.9rem;
}

/* ── Login screen ──────────────────────────────────────────────────────── */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-card .login-brand {
  text-align: center;
  margin-bottom: 8px;
}

.login-card .login-brand h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  color: var(--brand);
}

.login-card .login-brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-card .login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-card .login-field label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.login-card .login-field input {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 11px 14px;
  font-size: 0.95rem;
}

.login-card .login-field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.login-card .login-btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  transition: background 140ms ease;
}

.login-card .login-btn:hover {
  background: var(--brand-2);
}

.login-card .login-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.login-card .login-error {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  display: none;
}

.login-card .login-error.visible {
  display: block;
}

/* ── Sidebar footer (logout) ───────────────────────────────────────────── */

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-footer .user-info {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0 4px;
}

.sidebar-footer .user-info strong {
  color: var(--text);
  font-weight: 600;
}

.logout-btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 140ms ease, color 140ms ease;
  text-align: left;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    padding: 16px;
  }

  .main-panel {
    max-height: none;
    padding: 16px;
  }

  .main-header {
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }
}

/* ── Import & mapping flow ─────────────────────────────────────────────── */

.detail-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.form-control {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 9px 12px;
  font: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

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

.form-feedback {
  margin-top: 4px;
}

.clickable-row {
  cursor: pointer;
}

/* ── PO Detail ─────────────────────────────────────────────────────────── */

.po-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.po-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.po-meta {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.po-meta strong {
  color: var(--text);
}

.po-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

/* ── Activity Timeline ──────────────────────────────────────────────────── */

.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
}

.timeline-item {
  display: flex;
  gap: 0.75rem;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}

.timeline-item:last-child {
  border-bottom: none;
}

.timeline-date {
  color: var(--muted);
  white-space: nowrap;
  min-width: 140px;
  font-size: 0.8rem;
}

.timeline-action {
  font-weight: 600;
  text-transform: capitalize;
  min-width: 100px;
}

.timeline-details {
  color: var(--muted);
  flex: 1;
}

/* ── Receive form ───────────────────────────────────────────────────────── */

.receive-form-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}

.receive-form-row:last-child {
  border-bottom: none;
}

.receive-form-row .product-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receive-form-row input[type="number"] {
  width: 70px;
  text-align: right;
}

/* ── Dashboard activity timeline ──────────────────────────────────────── */

.activity-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.activity-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  align-items: baseline;
  font-size: 0.88rem;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-time {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  min-width: 50px;
}

.activity-text {
  flex: 1;
  min-width: 0;
}

.activity-text a {
  color: var(--brand);
  text-decoration: none;
}

.activity-text a:hover {
  text-decoration: underline;
}

/* ── Quick actions bar ───────────────────────────────────────────────── */

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
