/* =============================================================================
   Export Orders Management — application stylesheet.

   The design system is carried over from the approved HTML prototype: the same
   "Green ERP" palette, radii, badge treatments, table styling and card shells,
   so the refactored application looks like the prototype it replaces. What has
   changed is underneath — every screen is now driven by the live API instead of
   in-page fixtures.
   ============================================================================= */

:root {
  /* ── Green ERP theme (from the prototype) ── */
  --bg: #f0f7f2;
  --surface: #ffffff;
  --surface2: #e8f5ec;
  --white: #ffffff;
  --border: #c8e6c9;
  --border2: #a5d6a7;
  --line: #e3e7ef;

  --text-primary: #1b2e1e;
  --text-secondary: #4a6b50;
  --text-muted: #7fa885;
  --ink: #1a2233;

  /* Brand greens */
  --g-dark: #063d30;
  --g-mid: #0b6e56;
  --g-bright: #0e7d62;
  --g-light: #d1fae5;
  --g-pale: #ecfdf5;

  /* Semantic accents */
  --blue: #1976a8;      --blue-bg: #e3f2f8;   --blue-text: #0d4d70;
  --amber: #c47a0a;     --amber-bg: #fef3da;  --amber-text: #8a5200;
  --green: #063d30;     --green-bg: #d4f0dc;  --green-text: #0a3d1e;
  --red: #c0392b;       --red-bg: #fdecea;    --red-text: #7d1f16;
  --purple: #6a3bbf;    --purple-bg: #ede7fb; --purple-text: #3d1f87;
  --teal: #0b6e56;      --teal-bg: #d8f5ee;   --teal-text: #063d30;

  --accent: #0b6e56;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.45;
}

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

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

.app-header {
  background: linear-gradient(100deg, var(--g-dark), var(--g-mid));
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  position: sticky;
  top: 0;
  z-index: 300;
  box-shadow: 0 2px 8px rgba(6, 61, 48, .18);
  color: #fff;
}
.app-header .brand {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-header .brand small { font-weight: 500; opacity: .75; font-size: 11px; }
.app-header .session { display: flex; align-items: center; gap: 12px; font-size: 12px; }
.app-header .session .who { opacity: .9; }
.app-header .session button {
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .25);
  color: #fff;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.app-header .session button:hover { background: rgba(255, 255, 255, .24); }

.layout { display: flex; min-height: calc(100vh - 46px); }

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 0;
}
.sidebar nav { display: flex; flex-direction: column; }
.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-left: 3px solid transparent;
  background: none;
  border-top: 0; border-right: 0; border-bottom: 0;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.sidebar .nav-item:hover { background: var(--g-pale); color: var(--g-dark); }
.sidebar .nav-item.active {
  background: var(--g-pale);
  color: var(--g-dark);
  border-left-color: var(--g-mid);
  font-weight: 700;
}
.sidebar .nav-group {
  padding: 12px 18px 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.main { flex: 1; padding: 18px 22px 40px; min-width: 0; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.page-head h1 { font-size: 19px; margin: 0 0 3px; color: var(--g-dark); }
.page-head p { margin: 0; color: var(--text-secondary); font-size: 12.5px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

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

.card {
  background: var(--white);
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(20, 30, 60, .05);
  margin-bottom: 14px;
}
.card-head {
  padding: 11px 15px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 13.5px; color: var(--g-dark); }
.card-body { padding: 14px 15px; }
.card-body.tight { padding: 0; }

/* ── KPI tiles ────────────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 11px;
  margin-bottom: 14px;
}
.kpi {
  background: var(--white);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 13px 15px;
  position: relative;
  overflow: hidden;
}
.kpi .label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.kpi .value { font-size: 22px; font-weight: 700; color: var(--g-dark); margin-top: 3px; }
.kpi .sub { font-size: 11.5px; color: var(--text-secondary); margin-top: 1px; }
.kpi.accent { border-color: var(--border2); background: var(--g-pale); }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
}
.btn:hover:not(:disabled) { background: var(--g-pale); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--g-mid), var(--g-dark));
  color: #fff;
  border-color: var(--g-dark);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(135deg, var(--g-mid), var(--g-dark)); }
.btn-sec { background: #eef0f4; color: var(--ink); border: none; font-weight: 600; font-size: 12px; padding: 7px 13px; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); background: var(--red); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-darkgreen { background: var(--g-dark); color: #fff; }
.badge-blue { background: var(--blue-bg); color: var(--blue-text); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-red { background: var(--red-bg); color: var(--red-text); }
.badge-purple { background: var(--purple-bg); color: var(--purple-text); }
.badge-teal { background: var(--teal-bg); color: var(--teal-text); }
.badge-gray { background: #eceff1; color: #4a5560; }

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

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  padding: 7px 10px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--g-dark);
  border-bottom: 1px solid var(--border2);
  background: var(--green-bg);
  white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: var(--border2); }
th .sort-ind { opacity: .55; font-size: 9px; margin-left: 3px; }
td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover td { background: var(--g-pale); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-link { cursor: pointer; }

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 11px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.field label .req { color: var(--red); }
input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text-primary);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--g-mid);
  box-shadow: 0 0 0 3px rgba(11, 110, 86, .12);
}
input[readonly] { background: var(--surface2); color: var(--text-secondary); }
.field-error { color: var(--red-text); font-size: 11.5px; }
.field.has-error input,
.field.has-error select,
.field.has-error textarea { border-color: var(--red); }

.filters { display: flex; gap: 9px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 145px; }

/* ── States: loading / empty / error / denied ─────────────────────────────── */

.state {
  padding: 32px 18px;
  text-align: center;
  color: var(--text-secondary);
}
.state .state-title { font-weight: 700; color: var(--text-primary); margin-bottom: 4px; font-size: 14px; }
.state .state-msg { font-size: 12.5px; }
.state .state-actions { margin-top: 12px; }
.state-error .state-title { color: var(--red-text); }
.state-denied .state-title { color: var(--amber-text); }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--g-light);
  border-top-color: var(--g-mid);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, #eef2ee 25%, #f7faf8 50%, #eef2ee 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 4px;
  height: 11px;
  margin: 7px 0;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

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

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 25, 20, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 20px;
}
.modal {
  background: var(--white);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}
.modal.wide { max-width: 940px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 17px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 2;
}
.modal-title { font-size: 14.5px; font-weight: 700; color: var(--g-dark); margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
}
.modal-body { padding: 15px 17px; }
.modal-footer {
  padding: 12px 17px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  position: sticky;
  bottom: 0;
  background: var(--white);
}

/* ── Toasts ───────────────────────────────────────────────────────────────── */

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .16);
  max-width: 340px;
  background: var(--g-dark);
  color: #fff;
}
.toast.error { background: var(--red); }
.toast.warn { background: var(--amber); }

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

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--g-dark), var(--g-mid));
  padding: 20px;
}
.login-card {
  background: var(--white);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
  width: 100%;
  max-width: 380px;
  padding: 26px;
}
.login-card h1 { margin: 0 0 3px; font-size: 18px; color: var(--g-dark); }
.login-card p.sub { margin: 0 0 18px; font-size: 12.5px; color: var(--text-secondary); }
.login-card .field { margin-bottom: 12px; }
.login-card .btn { width: 100%; justify-content: center; }
.login-error {
  background: var(--red-bg);
  color: var(--red-text);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 12.5px;
  margin-bottom: 12px;
}

/* ── Detail / misc ────────────────────────────────────────────────────────── */

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 9px 18px; }
.kv .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 700; }
.kv .v { font-size: 13px; color: var(--text-primary); }

.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 10px 15px; font-size: 12.5px; color: var(--text-secondary); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 13px; flex-wrap: wrap; }
.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
}
.tabs button.active { color: var(--g-dark); border-bottom-color: var(--g-mid); }

.bar-row { display: flex; align-items: center; gap: 8px; margin: 5px 0; font-size: 12px; }
.bar-row .bar-label { flex: 0 0 132px; color: var(--text-secondary); }
.bar-row .bar-track { flex: 1; background: var(--surface2); border-radius: 10px; height: 15px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: linear-gradient(90deg, var(--g-mid), var(--g-bright)); }
.bar-row .bar-value { flex: 0 0 76px; text-align: right; font-weight: 600; color: var(--g-dark); }

.muted { color: var(--text-muted); }
.small { font-size: 11.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 12px; }
.hidden { display: none !important; }
.inline-actions { display: flex; gap: 5px; flex-wrap: wrap; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar .nav-item { width: auto; border-left: none; border-bottom: 3px solid transparent; }
  .sidebar .nav-item.active { border-left: none; border-bottom-color: var(--g-mid); }
  .sidebar .nav-group { display: none; }
}
