:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-bg: #0f172a;
  --sidebar-bg-hover: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #64748b;
  --card-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: white;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

header h1 {
  font-size: 20px;
  margin: 0;
}

header nav a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
  margin-left: 16px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* App shell (sidebar layout for internal/back-office pages) */

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 16px 0 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 4px 20px 16px;
  font-weight: 700;
  font-size: 17px;
  color: white;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 8px;
}

.sidebar-brand span {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--sidebar-muted);
  margin-top: 2px;
}

.sidebar-group {
  margin-top: 10px;
}

.sidebar-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 20px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.sidebar-group-title:hover {
  color: white;
}

.sidebar-caret {
  font-size: 10px;
  line-height: 1;
}

.sidebar-group-items {
  display: block;
}

.sidebar-group.collapsed .sidebar-group-items {
  display: none;
}

.sidebar-link {
  display: block;
  padding: 9px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background: var(--sidebar-bg-hover);
  color: white;
}

.sidebar-link.active {
  background: rgba(37, 99, 235, 0.18);
  border-left-color: var(--blue);
  color: white;
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 20px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer a {
  display: block;
  padding: 8px 0;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
}

.sidebar-footer a:hover {
  color: white;
}

.sidebar-toggle {
  display: none;
}

.content-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px;
  background: white;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 19px;
  margin: 0;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.content-area main {
  max-width: 1200px;
  width: 100%;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.2);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    cursor: pointer;
    font-size: 18px;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 30;
  }

  .sidebar-backdrop.open {
    display: block;
  }
}

.filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filters input {
  flex: 1;
  min-width: 140px;
}

input, select, button {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

button {
  background: var(--blue);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease, opacity 0.15s ease;
}

button:hover {
  background: var(--blue-dark);
}

button.secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: #f1f5f9;
}

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

button.danger:hover {
  background: #b91c1c;
}

.table-wrap {
  overflow-x: auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  margin-bottom: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  white-space: nowrap;
}

th {
  background: #f1f5f9;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}

tbody tr:hover {
  background: #f8fafc;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-pending, .badge-unvalidated {
  background: #fef3c7;
  color: #92400e;
}

.badge-approved, .badge-validated, .badge-active {
  background: #dcfce7;
  color: #166534;
}

.badge-rejected {
  background: #fee2e2;
  color: #991b1b;
}

.badge-neutral {
  background: #e2e8f0;
  color: var(--muted);
}

.badge-info {
  background: #dbeafe;
  color: #1e40af;
}

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

.login-card, .form-card {
  max-width: 420px;
  margin: 60px auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--card-shadow);
}

.form-card {
  max-width: 640px;
  margin: 0 auto 24px;
}

.form-card h2 {
  margin-top: 0;
  font-size: 17px;
}

.form-card h3 {
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 520px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.grid-2 > *, .grid-4 > * { min-width: 0; }

.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.field label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0;
}

.actions-row {
  display: flex;
  gap: 8px;
}

.upload-box {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  margin-bottom: 24px;
  background: white;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.steps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--muted);
}

.steps .step {
  padding: 4px 10px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--border);
}

.steps .step.active {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
  font-weight: 600;
}

.steps .step-sep {
  color: var(--border);
}

/* Date picker (datepicker.js) */
.dp-wrap { position: relative; display: inline-flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; }
.dp-wrap input { min-width: 0; width: 130px; }
.field .dp-wrap { display: flex; }
.field .dp-wrap input { flex: 1; width: auto; }
.dp-btn { padding: 4px 8px; line-height: 1; }
.dp-popup {
  position: absolute; top: 100%; left: 0; z-index: 50; margin-top: 4px; width: 250px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18); padding: 10px;
}
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.dp-title { font-weight: 600; font-size: 14px; }
.dp-nav, .dp-day, .dp-foot button { background: none; border: 0; color: var(--text); cursor: pointer; border-radius: 6px; padding: 4px 8px; }
.dp-nav:hover, .dp-day:hover, .dp-foot button:hover { background: var(--bg); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dp-dow { font-size: 11px; color: var(--muted); padding: 2px 0; }
.dp-day { padding: 5px 0; font-size: 13px; }
.dp-today { border: 1px solid var(--blue); }
.dp-sel, .dp-sel:hover { background: var(--blue); color: #fff; }
.dp-foot { display: flex; justify-content: space-between; margin-top: 6px; font-size: 13px; }

/* MAWB list / detail (TransOn-style layout) */
.list-panel { background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); padding: 12px 16px 16px; margin-bottom: 20px; }
.list-panel-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.list-panel-actions a button, .list-panel-actions button { background: #fff; color: var(--text); border: 1px solid var(--border); font-size: 13px; padding: 6px 12px; }
.list-panel-actions a button:hover { border-color: var(--blue); color: var(--blue); }
.filter-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.filter-row select, .filter-row input { padding: 7px 10px; font-size: 13px; min-width: 130px; }
.seg { display: inline-flex; background: var(--bg); border-radius: 6px; padding: 2px; gap: 2px; }
.seg button { background: none; border: 0; color: var(--text); font-size: 13px; padding: 5px 10px; border-radius: 5px; cursor: pointer; }
.seg button.on { background: var(--blue); color: #fff; }
.date-range { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 8px; padding: 0 8px; background: #fff; }
.date-range .dp-wrap input { border: 0; width: 100px; padding: 7px 4px; font-size: 13px; }
.date-range .dp-wrap input:focus { outline: none; }
.date-range .dp-btn { display: none; }
.group-head { padding: 12px 16px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); }
.chip-blue { background: #eff6ff; color: #1e40af; border-color: #dbeafe; }
.num { text-align: right; white-space: nowrap; }
.doc-link { color: var(--blue); cursor: pointer; text-decoration: none; }

.detail-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.detail-bar .actions-row { margin: 0; }
.back-btn { background: #fff; color: var(--text); border: 1px solid var(--border); padding: 6px 12px; text-decoration: none; border-radius: 8px; font-size: 16px; line-height: 1; }
.info-strip { display: flex; gap: 24px; flex-wrap: wrap; align-items: center; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; font-size: 13px; color: var(--muted); }
.info-strip b { color: var(--text); }
.section-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); margin-bottom: 16px; }
.section-card > h2 { font-size: 14px; margin: 0; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.section-card > .section-body { padding: 16px; }
.field-upper label { text-transform: uppercase; font-size: 11px; letter-spacing: 0.03em; }
.id-row { display: flex; gap: 8px; align-items: center; }
.id-row input { flex: 1; min-width: 0; }
.id-row button { white-space: nowrap; }
.input-warn { border-color: var(--warning) !important; }
.warn-text { color: var(--warning); font-size: 12px; margin: 4px 0 8px; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch .slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + .slider { background: var(--blue); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-3 > * { min-width: 0; }
.grid-4-fluid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid-4-fluid > * { min-width: 0; }
@media (max-width: 720px) { .grid-3, .grid-4-fluid { grid-template-columns: 1fr 1fr; } }
.field .dp-wrap .dp-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; padding: 2px 4px; box-shadow: none; }
.field .dp-wrap input { padding-right: 34px; }
.sc-table { width: 100%; min-width: 0; table-layout: fixed; border-collapse: collapse; margin-bottom: 8px; }
.sc-table th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 4px; }
.sc-table td { padding: 3px 4px; }
.sc-table input { width: 100%; min-width: 0; box-sizing: border-box; padding: 6px 8px; }
.sc-table button { padding: 4px 8px; }
.section-body h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Dashboard */
.dash-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.dash-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--card-shadow); padding: 14px 16px; }
.dash-num { font-size: 28px; font-weight: 600; margin-top: 4px; }
.dash-split { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; margin-bottom: 16px; }
.attn > div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.attn > div:last-child { border-bottom: 0; }
.attn a { margin-left: 10px; color: var(--blue); }
.quick { display: grid; gap: 8px; }
.quick a button { width: 100%; }
@media (max-width: 900px) { .dash-cards { grid-template-columns: 1fr 1fr; } .dash-split { grid-template-columns: 1fr; } }
