/* ===========================================================
   SPOSAKU WORKS - スタイルシート
   =========================================================== */

:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eaeee9;
  --text: #16211c;
  --text-muted: #5b6a62;
  --border: #d9ded8;
  --primary: #0f6b5c;
  --primary-dark: #0a4b40;
  --primary-tint: #e2f0ec;
  --accent: #d9601f;
  --accent-tint: #fbe7d8;
  --success: #2e7d46;
  --success-tint: #e3f2e6;
  --warning: #a5770a;
  --warning-tint: #fbf0d8;
  --danger: #c0392b;
  --danger-tint: #fbe3e0;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 14px rgba(20, 30, 25, .06);
  --font-ui: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101612;
    --surface: #19221d;
    --surface-2: #212b24;
    --text: #e9efe8;
    --text-muted: #98a99f;
    --border: #2c3830;
    --primary: #49b79e;
    --primary-dark: #337f6c;
    --primary-tint: #1a332c;
    --accent: #ff9257;
    --accent-tint: #3a2618;
    --success: #5cbb79;
    --success-tint: #1a2f20;
    --warning: #d9ac4c;
    --warning-tint: #33290f;
    --danger: #e37568;
    --danger-tint: #3a1e1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 20px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --bg: #101612;
  --surface: #19221d;
  --surface-2: #212b24;
  --text: #e9efe8;
  --text-muted: #98a99f;
  --border: #2c3830;
  --primary: #49b79e;
  --primary-dark: #337f6c;
  --primary-tint: #1a332c;
  --accent: #ff9257;
  --accent-tint: #3a2618;
  --success: #5cbb79;
  --success-tint: #1a2f20;
  --warning: #d9ac4c;
  --warning-tint: #33290f;
  --danger: #e37568;
  --danger-tint: #3a1e1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 20px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { text-wrap: balance; margin: 0 0 .4em; font-weight: 700; }
a { color: inherit; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- topbar --------------------------------------------------- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left, 0px)) 10px max(16px, env(safe-area-inset-right,0px));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 16px;
}
.brand-text { font-weight: 700; letter-spacing: .02em; font-size: 16px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); font-size: 17px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--primary); }

/* ---- layout ----------------------------------------------------- */
.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-left, 0px)) 60px max(16px, env(safe-area-inset-right, 0px));
}
.footer {
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
}

/* ---- top page: job grid ----------------------------------------- */
.page-head { margin-bottom: 20px; }
.page-head .eyebrow { color: var(--primary); font-weight: 700; font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; }
.page-head h1 { font-size: 22px; margin-top: 4px; }
.page-head p { color: var(--text-muted); margin: 4px 0 0; }

.job-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.job-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--job-color, var(--primary));
  border-radius: var(--radius-m);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.job-card:hover { transform: translateY(-2px); }
.job-card .job-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--job-color, var(--primary));
  color: #fff; font-weight: 900; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.job-card h3 { font-size: 16px; margin-bottom: 4px; }
.job-card p { margin: 0; color: var(--text-muted); font-size: 13px; }

/* ---- job workspace ------------------------------------------------ */
.workspace-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-muted); text-decoration: none; font-size: 13px;
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
  background: var(--surface);
}
.back-link:hover { color: var(--text); }
.workspace-title { display: flex; align-items: center; gap: 10px; }
.workspace-title .job-icon-sm {
  width: 30px; height: 30px; border-radius: 8px; color: #fff; font-weight: 900;
  display: flex; align-items: center; justify-content: center; background: var(--job-color, var(--primary));
  font-size: 13px;
}
.workspace-title h1 { font-size: 19px; margin: 0; }
.workspace-title p { margin: 0; color: var(--text-muted); font-size: 12.5px; }

.tabs {
  display: flex; gap: 6px; overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px; padding-bottom: 0;
}
.tab-btn {
  border: none; background: transparent; cursor: pointer;
  padding: 10px 14px; font-size: 13.5px; font-weight: 500;
  color: var(--text-muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

.subtabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip-btn {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); border-radius: 999px; padding: 6px 14px;
  font-size: 12.5px; cursor: pointer;
}
.chip-btn.active { background: var(--primary-tint); border-color: var(--primary); color: var(--primary-dark); font-weight: 700; }

/* ---- panels / cards ------------------------------------------------ */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-m); padding: 18px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.panel h2 { font-size: 15px; margin-bottom: 14px; }
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---- forms ------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: 9px 10px;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input[type="number"] { font-family: var(--font-mono); }

.btn {
  border: 1px solid transparent; border-radius: var(--radius-s);
  padding: 9px 16px; font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary-dark); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- tables ------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-m); }
table { border-collapse: collapse; width: 100%; min-width: 560px; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th { background: var(--surface-2); color: var(--text-muted); font-weight: 700; font-size: 12px; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.empty-row td { text-align: center; color: var(--text-muted); padding: 26px; font-family: var(--font-ui); }

.rank-chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 22px; padding: 0 6px; border-radius: 6px;
  font-family: var(--font-mono); font-weight: 700; font-size: 12px;
}
.rank-S { background: var(--accent-tint); color: var(--accent); }
.rank-A { background: var(--success-tint); color: var(--success); }
.rank-B { background: var(--primary-tint); color: var(--primary-dark); }
.rank-C { background: var(--warning-tint); color: var(--warning); }
.rank-D { background: var(--danger-tint); color: var(--danger); }
.rank-NA { background: var(--surface-2); color: var(--text-muted); }

.type-badge { display: inline-flex; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.type-in { background: var(--primary-tint); color: var(--primary-dark); }
.type-out { background: var(--accent-tint); color: var(--accent); }

/* ---- order items editor -------------------------------------------- */
.items-editor { display: flex; flex-direction: column; gap: 8px; }
.item-row { display: grid; grid-template-columns: 1fr 90px 120px 32px; gap: 8px; align-items: center; }
.item-row .rm-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.totals-line { display: flex; justify-content: flex-end; gap: 22px; margin-top: 10px; font-family: var(--font-mono); }
.totals-line b { font-family: var(--font-ui); font-weight: 500; color: var(--text-muted); margin-right: 6px; }

/* ---- dialog / settings --------------------------------------------- */
.dialog {
  border: none; border-radius: var(--radius-l); padding: 0;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); width: min(440px, 92vw);
}
.dialog::backdrop { background: rgba(10, 16, 13, .45); }
.settings-form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.settings-form h2 { font-size: 16px; }
.hint { color: var(--text-muted); font-size: 12.5px; margin: -6px 0 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---- toast ---------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; z-index: 100;
  box-shadow: var(--shadow);
}

/* ---- print area (screen: hidden) ------------------------------------ */
.print-area { display: none; }

/* ---- responsive ------------------------------------------------------ */
@media (max-width: 600px) {
  .brand-text { display: none; }
  .item-row { grid-template-columns: 1fr; }
  .totals-line { flex-direction: column; align-items: flex-end; gap: 4px; }
}

/* ===========================================================
   印刷スタイル（控え・発注書・受注伝票）
   =========================================================== */
@media print {
  .topbar, .footer, #app, .toast { display: none !important; }
  .print-area { display: block !important; }
  body { background: #fff; color: #111; font-size: 12.5pt; }
  .slip { width: 100%; max-width: 720px; margin: 0 auto; padding: 10mm; }
  .slip-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #111; padding-bottom: 10px; margin-bottom: 16px; }
  .slip-head h1 { font-size: 20pt; margin: 0; letter-spacing: .1em; }
  .slip-meta { text-align: right; font-size: 10.5pt; }
  .slip-parties { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
  .slip-parties .party { font-size: 11pt; }
  .slip-parties .party b { display: block; font-size: 13pt; border-bottom: 1px solid #111; padding-bottom: 4px; margin-bottom: 4px; }
  .slip table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
  .slip th, .slip td { border: 1px solid #333; padding: 6px 8px; font-size: 10.5pt; }
  .slip th { background: #eee; }
  .slip td.num, .slip th.num { text-align: right; font-variant-numeric: tabular-nums; }
  .slip-total { display: flex; justify-content: flex-end; }
  .slip-total table { width: 260px; }
  .slip-stamp { margin-top: 26px; display: flex; justify-content: flex-end; }
  .slip-stamp .box { width: 130px; height: 60px; border: 1px solid #111; display: flex; align-items: flex-start; justify-content: center; font-size: 9pt; color: #555; padding-top: 4px; }
}
