:root {
  --bg: #fbf8f4;
  --bg-card: #fff;
  --border: #ebe4d8;
  --border-2: #d5cdbc;
  --text: #2a2a2a;
  --text-muted: #777;
  --accent: #1f1f1f;
  --accent-hover: #000;
  --primary: #c45a2c;
  --primary-hover: #a8491f;
  --success: #2f7a3e;
  --success-bg: #e9f5ec;
  --warn: #c4761b;
  --warn-bg: #fbf0d8;
  --info-bg: #eef2f7;
  --danger: #b13b3b;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif; font-size: 14px; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* === LOGIN === */
.page-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 100%; max-width: 360px; box-shadow: 0 4px 16px rgba(0,0,0,0.04); }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card label { display: block; margin-top: 16px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-2); border-radius: var(--radius); font-size: 15px; margin-top: 6px; outline: none; background: #fff; }
.login-card input:focus { border-color: var(--primary); }
.login-card .err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* === APP === */
.page-app { min-height: 100vh; }
.topbar { background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 16px; padding: 0 20px; min-height: 56px; position: sticky; top: 0; z-index: 30; }
.brand { font-weight: 700; font-size: 16px; }
.nav { display: flex; gap: 4px; }
.nav-link { padding: 8px 14px; border-radius: 6px; font-size: 14px; color: var(--text-muted); }
.nav-link:hover { background: var(--info-bg); color: var(--text); }
.nav-link.active { color: var(--text); font-weight: 700; }
.spacer { flex: 1; }
.user { font-size: 13px; color: var(--text-muted); }

.container { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
.view-title { font-size: 22px; font-weight: 700; margin-bottom: 16px; }

/* dashboard cards */
.dash { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.dash-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; cursor: pointer; transition: border .15s; }
.dash-card:hover { border-color: var(--primary); }
.dash-label { color: var(--text-muted); font-size: 13px; margin-bottom: 4px; }
.dash-num { font-size: 28px; font-weight: 700; }
.dash-card[data-status="未処理"] .dash-num { color: var(--primary); }
.dash-card[data-status="処理中"] .dash-num { color: var(--warn); }
.dash-card[data-status="発送済"] .dash-num { color: var(--success); }
.dash-card[data-status="完了"] .dash-num { color: var(--text-muted); }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; background: var(--info-bg); padding: 3px; border-radius: 8px; }
.tab { background: transparent; border: 0; padding: 7px 14px; border-radius: 6px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.tab.active { background: var(--accent); color: #fff; }
.input, .select { padding: 8px 10px; border: 1px solid var(--border-2); border-radius: var(--radius); font-size: 14px; background: #fff; outline: none; }
.input { min-width: 240px; flex: 1; max-width: 360px; }
.input:focus, .select:focus { border-color: var(--primary); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--border-2); background: #fff; color: var(--text); border-radius: var(--radius); font-size: 14px; font-weight: 600; transition: background .12s, border .12s; }
.btn:hover { background: var(--info-bg); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; margin-top: 16px; padding: 12px; }
.btn-link { background: transparent; border: 0; color: var(--text-muted); }
.btn-link:hover { background: transparent; color: var(--text); }

/* orders table */
.table-wrap { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; overflow-x: auto; }
.orders-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.orders-table colgroup .col-product { width: auto; }
.orders-table th:nth-child(1) { width: 88px; }
.orders-table th:nth-child(2) { width: 220px; }
.orders-table th:nth-child(4) { width: 50px; }
.orders-table th:nth-child(5) { width: 90px; }
.orders-table th:nth-child(6) { width: 80px; }
.orders-table th:nth-child(7) { width: 100px; }
.orders-table th:nth-child(8) { width: 70px; }
.orders-table th { text-align: left; padding: 10px 12px; font-weight: 700; color: var(--text-muted); border-bottom: 1px solid var(--border); background: #fafaf8; font-size: 12px; white-space: nowrap; }
.orders-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.orders-table tr:last-child td { border-bottom: 0; }
.orders-table tr:hover td { background: #fcfaf6; }
.empty { text-align: center; color: var(--text-muted); padding: 40px 0 !important; }

.cell-date { white-space: nowrap; width: 90px; }
.cell-order-id { font-family: ui-monospace, "SF Mono", monospace; font-size: 12px; white-space: nowrap; width: 200px; }
.cell-order-id .oid-line, .cell-order-id .sku-line, .cell-order-id .region-line { display: flex; align-items: center; gap: 4px; }
.cell-order-id .oid { font-weight: 600; font-size: 12px; }
.cell-order-id .sku-line { margin-top: 3px; }
.cell-order-id .sku { font-size: 12px; color: var(--text-muted); }
.cell-order-id .region-line { margin-top: 4px; }
.cell-order-id .region-badge { font-family: -apple-system, sans-serif; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px; background: var(--info-bg); color: var(--text); }
.cell-order-id .muted { color: var(--text-muted); font-style: italic; }
.copy-btn { background: transparent; border: 0; padding: 2px 6px; font-size: 12px; cursor: pointer; border-radius: 4px; color: var(--text-muted); transition: background .1s, color .1s; }
.copy-btn:hover { background: var(--info-bg); color: var(--text); }
.copy-btn.copied { background: var(--success-bg); color: var(--success); }
.th-product { width: 100%; }
.cell-product { min-width: 280px; }
.cell-product .title { line-height: 1.4; word-break: break-word; }
.cell-product .var { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.cell-region { font-weight: 700; width: 40px; text-align: center; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-mishori { background: #fdecdf; color: var(--primary); }
.badge-shoricyu { background: var(--warn-bg); color: var(--warn); }
.badge-hassou   { background: var(--success-bg); color: var(--success); }
.badge-kanryo   { background: #eee; color: #555; }
.badge-toritage { background: #f3e8e8; color: var(--danger); }

.label-on { color: var(--success); font-weight: 700; }
.label-off { color: var(--text-muted); }
.cell-label { white-space: nowrap; }
.label-link { display: inline-block; padding: 3px 10px; background: var(--success-bg); color: var(--success); border-radius: 6px; font-weight: 700; font-size: 12px; text-decoration: none; }
.label-link:hover { background: var(--success); color: #fff; }
.btn-label-up { background: var(--primary); color: #fff; border: 0; padding: 5px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; }
.btn-label-up:hover { background: var(--primary-hover); }
.btn-self { background: var(--info-bg); color: var(--text); border: 1px solid var(--border-2); padding: 6px 12px; font-size: 12px; font-weight: 600; }
.btn-self:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* panels (sync view) */
.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.panel h3 { font-size: 15px; margin-bottom: 8px; }
.panel .muted { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.panel input[type="file"] { margin-right: 12px; }
.result { font-family: ui-monospace, monospace; font-size: 13px; margin-top: 12px; padding: 8px 12px; background: var(--info-bg); border-radius: 6px; min-height: 24px; }
.result.ok { background: var(--success-bg); color: var(--success); }
.result.err { background: #fbeaea; color: var(--danger); }
.sync-history { width: 100%; border-collapse: collapse; font-size: 13px; }
.sync-history th, .sync-history td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.sync-history th { color: var(--text-muted); font-size: 12px; font-weight: 700; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 12px; max-width: 520px; width: 100%; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { flex: 1; font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.kv { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0; font-size: 13px; border-bottom: 1px dashed var(--border); }
.kv span { width: 120px; flex-shrink: 0; color: var(--text-muted); }
.kv b { flex: 1; word-break: break-all; }
.lbl { display: block; margin-top: 14px; font-size: 13px; font-weight: 600; }
.lbl .select, .lbl textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border-2); border-radius: var(--radius); font-size: 14px; font-family: inherit; }
.lbl textarea { resize: vertical; }
.history { list-style: none; margin-top: 8px; font-size: 12px; }
.history li { padding: 4px 0; border-bottom: 1px dashed var(--border); }
.history time { color: var(--text-muted); margin-right: 6px; }
