/* ===== base ===== */
:root {
  --accent: #2563eb;
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --side: #1b2433; --side-text: #c9d1dd; --side-hover: #263246;
  --ok: #15803d; --ok-bg: #e7f6ec; --ng: #b91c1c; --ng-bg: #fdecec; --warn-bg: #fff6dd; --warn: #92400e;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --card: #171b23; --text: #e3e7ee; --muted: #9aa3b2; --line: #2a303b;
    --side: #0b0e13; --side-hover: #1a202b;
    --ok-bg: #12301d; --ok: #6ee7a0; --ng-bg: #3a1616; --ng: #fca5a5; --warn-bg: #3a2e10; --warn: #fcd34d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 14px; line-height: 1.6; background: var(--bg); color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ===== layout ===== */
body.has-nav { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
body.is-admin .sidebar { background: color-mix(in srgb, var(--side) 82%, var(--accent)); }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; color: #fff; font-weight: 700; text-decoration: none !important; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--side-text); }
.logo { background: var(--accent); color: #fff; border-radius: 6px; padding: 4px 6px; font-size: 12px; letter-spacing: .05em; }
.sidebar nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; flex: 1; }
.sidebar nav a { color: var(--side-text); padding: 9px 12px; border-radius: 6px; text-decoration: none; }
.sidebar nav a:hover { background: var(--side-hover); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.me { border-top: 1px solid rgba(255,255,255,.08); padding: 14px 16px; font-size: 13px; }
.me-name { color: #fff; }
.me-sub { font-size: 12px; margin-bottom: 6px; }
button.link { background: none; border: 0; padding: 0; color: var(--side-text); text-decoration: underline; cursor: pointer; font: inherit; font-size: 12px; }

.page { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--card); }
.topbar h1 { font-size: 18px; margin: 0; }
.srv { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.srv .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.srv .az { border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; }
.srv .switched { background: var(--warn-bg); color: var(--warn); border-radius: 999px; padding: 0 8px; }
.content { padding: 20px 24px; flex: 1; width: 100%; max-width: 1200px; }
.foot { padding: 10px 24px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); }

@media (max-width: 820px) {
  body.has-nav { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .me { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}

/* ===== components ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-ng { background: var(--ng-bg); color: var(--ng); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: color-mix(in srgb, var(--bg) 60%, var(--card)); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.tbl tfoot td { font-weight: 600; border-bottom: 0; }
.tbl-wrap { overflow-x: auto; }
tr.inactive td { opacity: .5; }

.st { display: inline-block; font-size: 12px; padding: 1px 9px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.st-submitted { background: #e8f0fe; color: #1d4ed8; }
.st-accepted  { background: #efe7fd; color: #6d28d9; }
.st-shipped   { background: #fff4de; color: #b45309; }
.st-delivered { background: #e7f6ec; color: #15803d; }
.st-cancelled { background: #eef0f3; color: #6b7280; }
@media (prefers-color-scheme: dark) {
  .st { background: transparent !important; border-color: currentColor; }
  .st-submitted { color: #93b4ff; } .st-accepted { color: #c4a6ff; } .st-shipped { color: #fbbf5a; } .st-delivered { color: #6ee7a0; }
}
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; color: var(--muted); }

/* ===== forms ===== */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input.qty { width: 80px; text-align: right; }
textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.filters > div { min-width: 140px; }

.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: #fff; border: 1px solid var(--accent);
  border-radius: 6px; padding: 7px 14px; font: inherit; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { filter: brightness(1.08); }
.btn-sub { background: transparent; color: var(--text); border-color: var(--line); }
.btn-danger { background: transparent; color: var(--ng); border-color: currentColor; }
.btn-sm { padding: 3px 10px; font-size: 12.5px; }
.inline { display: inline; }

/* ===== login ===== */
body.no-nav .page { min-height: 100vh; justify-content: center; align-items: center; }
body.no-nav .content { max-width: 420px; flex: 0 0 auto; margin: auto 0; }
.login-card { padding: 28px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }
.demo-accounts { font-size: 12px; color: var(--muted); margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 12px; }

/* 狭い画面ではテーブルを横スクロール */
.tbl-wrap .tbl { min-width: 640px; }
.tag, .st { white-space: nowrap; }

/* フォームのエラー表示・ページ送り */
.is-invalid { border-color: var(--ng) !important; }
.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 14px; font-size: 13px; }
.btn.disabled { opacity: .4; pointer-events: none; }
