:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #2a3343;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #2ea043;
  --accent-2: #1f6feb;
  --danger: #da3633;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ------------------------------- Login --------------------------------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #14233b 0%, var(--bg) 60%);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 340px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.login-logo { font-size: 44px; }
.login-card h1 { font-size: 18px; letter-spacing: 0.5px; margin: 12px 0 2px; }
.login-card input {
  width: 100%;
  margin: 18px 0 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.login-card button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.login-error { color: var(--danger); margin-top: 12px; min-height: 18px; }

/* ------------------------------- Layout -------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 58px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand span { letter-spacing: 0.4px; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: #fff; background: var(--accent-2); }
.topbar .ghost { margin-left: auto; }

main { padding: 22px; max-width: 1200px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ------------------------------ Buttons -------------------------------- */

button { font-family: inherit; }
.primary, .ghost, .danger, .icon-btn {
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.ghost { background: var(--panel-2); color: var(--text); }
.ghost:hover { background: #243044; }
.danger { background: transparent; color: var(--danger); border-color: #5c2b2b; }
.danger:hover { background: rgba(218, 54, 51, 0.12); }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 18px; }

/* ------------------------------- Stats --------------------------------- */

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 130px;
  flex: 1;
}
.stat-n { font-size: 20px; font-weight: 700; }
.stat-l { color: var(--muted); margin-top: 4px; font-size: 12px; }

/* ------------------------------ Toolbar -------------------------------- */

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar h2 { margin: 0; font-size: 18px; }
.spacer { flex: 1; }
select, input, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; width: 100%; }

/* ------------------------------- Tables -------------------------------- */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--panel-2); }
.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 6px 10px; font-size: 13px; }
td code { background: var(--bg); padding: 2px 6px; border-radius: 5px; color: #79c0ff; }
.pad { padding: 24px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ------------------------------- Pills --------------------------------- */

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.pill.payment_review { background: rgba(210, 153, 34, 0.15); color: #d29922; border-color: #5c4a1d; }
.pill.awaiting_payment { background: rgba(139, 152, 169, 0.12); color: var(--muted); }
.pill.paid { background: rgba(46, 160, 67, 0.15); color: #3fb950; border-color: #265e34; }
.pill.shipped { background: rgba(31, 111, 235, 0.15); color: #58a6ff; border-color: #1f4173; }
.pill.completed { background: rgba(46, 160, 67, 0.2); color: #3fb950; border-color: #2ea043; }
.pill.cancelled, .pill.payment_rejected { background: rgba(218, 54, 51, 0.13); color: #f85149; border-color: #5c2b2b; }

/* ------------------------------- Modal --------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 460px; max-width: 100%;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}
.modal.wide { width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; }
.field.check { display: flex; align-items: center; gap: 8px; }
.field.check input { width: auto; }
.field.check span { margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; max-width: 560px; }

/* --------------------------- Order detail ------------------------------ */

.order-grid { display: grid; grid-template-columns: 1fr 280px; gap: 22px; }
table.mini { margin-bottom: 16px; }
table.mini td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.mini tr.total td { border-top: 1px solid var(--border); }
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.kv span { color: var(--muted); }
.proof-col { border-left: 1px solid var(--border); padding-left: 18px; }
.proof { width: 100%; border-radius: 10px; border: 1px solid var(--border); margin-top: 8px; }
.ref { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-top: 8px; word-break: break-word; }

@media (max-width: 760px) {
  main { padding: 14px; }

  /* Topbar: brand + logout on row 1, horizontally-scrollable tabs on row 2 */
  .topbar { height: auto; flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .brand { font-size: 14px; }
  .topbar .ghost { margin-left: auto; order: 2; }
  .tabs {
    order: 3;
    flex-basis: 100%;
    margin-left: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; }

  /* Stats: two cards per row */
  .stats { gap: 8px; }
  .stat { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 12px 14px; }
  .stat-n { font-size: 18px; }

  /* Toolbars wrap; title takes its own line */
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar h2 { width: 100%; }
  .toolbar .spacer { display: none; }
  .toolbar select, .toolbar input { flex: 1 1 auto; min-width: 0; }

  /* 16px form fields so iOS doesn't zoom on focus */
  input, select, textarea { font-size: 16px; }

  /* Card-stacked page tables (scoped so modal .mini tables are untouched) */
  .table-wrap { background: transparent; border: none; overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { position: absolute; left: -9999px; }
  .table-wrap tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 4px 14px;
  }
  .table-wrap tr.clickable:hover { background: var(--panel); }
  .table-wrap td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
    word-break: break-word;
  }
  .table-wrap tr td:last-child { border-bottom: none; }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: left;
    white-space: nowrap;
    flex: 0 0 auto;
  }
  .table-wrap td.row-actions { justify-content: flex-end; gap: 8px; padding-top: 12px; }
  .table-wrap td.row-actions::before { content: none; }
  .table-wrap td.row-actions button { flex: 1 1 auto; padding: 10px; }

  /* Modals: full width, stacked form rows + order detail */
  .modal-backdrop { padding: 12px; }
  .modal, .modal.wide { width: 100%; }
  .row2 { grid-template-columns: 1fr; }
  .order-grid { grid-template-columns: 1fr; }
  .proof-col { border-left: none; padding-left: 0; border-top: 1px solid var(--border); padding-top: 14px; }

  /* Login card fits narrow screens */
  .login-body { padding: 16px; }
  .login-card { width: 100%; max-width: 360px; padding: 28px 22px; }
  .login-card input { font-size: 16px; }
}
