*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f14;
  --surface: #1a1a24;
  --surface2: #22222f;
  --border: #2e2e3e;
  --accent: #4f8ef7;
  --green: #34d399;
  --red: #f87171;
  --text: #e8e8f0;
  --text2: #8888aa;
  --text3: #555570;
  --row-hover: rgba(255, 255, 255, .02);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f0e8;
    --surface: #fdfaf4;
    --surface2: #ede8df;
    --border: #d9d2c5;
    --accent: #2f6de0;
    --green: #16a34a;
    --red: #dc2626;
    --text: #1a1710;
    --text2: #6b6455;
    --text3: #a89e8e;
    --row-hover: rgba(0, 0, 0, .03);
  }
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body { overscroll-behavior-y: none; }
main { max-width: 640px; min-height: 100vh; margin: 0 auto; }

.porder-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.back-link,
#add-order,
#reload,
#cancel-edit,
#save-edit,
.icon-button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.back-link { display: inline-flex; align-items: center; padding: 0 11px; }
#reload { padding: 0 14px; background: var(--accent); border-color: var(--accent); color: white; }
#add-order { padding: 0 12px; }
button:disabled { opacity: .45; cursor: default; }
.back-link:focus-visible,
button:focus-visible,
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.order-count {
  min-width: 0;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}
.order-count strong {
  display: inline-block;
  min-width: 24px;
  margin-left: 4px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.status-row {
  display: flex;
  padding: 8px 12px 0;
  color: var(--text3);
  font-size: 11px;
  line-height: 1.35;
}
#notice { min-width: 0; overflow-wrap: anywhere; }
#notice.error { color: var(--red); }

.orders {
  margin: 8px 12px 28px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 320px;
  border-collapse: collapse;
  table-layout: fixed;
  text-align: left;
}
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
th {
  background: var(--surface2);
  color: var(--text2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .45px;
  text-transform: uppercase;
}
th:nth-child(1) { width: 58px; }
th:nth-child(2) { width: 82px; }
th:nth-child(3) { width: 82px; }
th:nth-child(4) { width: 88px; }
td {
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.account-mark { margin-left: 2px; color: var(--red); font-weight: 800; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }

.symbol-button {
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

#order-editor {
  width: min(340px, calc(100vw - 28px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
#order-editor::backdrop { background: rgba(0, 0, 0, .58); backdrop-filter: blur(2px); }
#edit-form { display: grid; gap: 8px; padding: 14px; }
.create-only { display: grid; gap: 8px; }
#order-editor[data-mode="edit"] .create-only { display: none; }
.card-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
#edit-symbol { color: var(--green); font-size: 20px; }
.icon-button { width: 36px; min-height: 36px; font-size: 22px; line-height: 1; }
#edit-form label { color: var(--text2); font-size: 12px; font-weight: 600; }
#edit-form input {
  width: 100%;
  height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
#cancel-edit, #save-edit { min-height: 42px; }
#save-edit { background: var(--accent); border-color: var(--accent); color: white; }

#empty { padding: 40px 18px; color: var(--text2); text-align: center; }
#empty h2 { margin-bottom: 6px; color: var(--text); font-size: 15px; font-weight: 600; }
#empty p { color: var(--text3); font-size: 12px; line-height: 1.5; }

@media (max-width: 520px) {
  main { max-width: 100%; }
  .porder-toolbar { padding: 9px 10px; }
  .status-row { padding-left: 10px; padding-right: 10px; }
  .orders { margin-left: 8px; margin-right: 8px; border-radius: 10px; }
  .back-link, #add-order, #reload { min-height: 40px; }
}
