/* styles.css — kanri-crm デザイントークン＋コンポーネント */

:root {
  --bg: #F4F5F8;
  --surface: #FFFFFF;
  --surface-2: #FAFAFC;
  --ink: #1A1D29;
  --muted: #6B7280;
  --faint: #9AA1AE;
  --brand: #4F46E5;
  --brand-strong: #4338CA;
  --brand-weak: #EEF0FF;
  --pos: #059669;
  --pos-weak: #E7F6F0;
  --neg: #DC2626;
  --neg-weak: #FCEBEB;
  --warn: #B45309;
  --warn-weak: #FDF3E7;
  --line: #E7E8EE;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --radius: 16px;
  --radius-sm: 10px;
  --cat-1: #4F46E5; --cat-2: #0EA5E9; --cat-3: #10B981; --cat-4: #F59E0B; --cat-5: #EF4444; --cat-6: #8B5CF6;
  --sans: 'Noto Sans JP', system-ui, -apple-system, sans-serif;
  --num: 'Inter', var(--sans);
}

:root[data-theme="dark"] {
  --bg: #0E1017;
  --surface: #171A23;
  --surface-2: #1E222E;
  --ink: #EBECF0;
  --muted: #9AA1AE;
  --faint: #6B7280;
  --brand: #7C74F5;
  --brand-strong: #9A93FF;
  --brand-weak: #23233A;
  --pos: #34D399;
  --pos-weak: #16281F;
  --neg: #F87171;
  --neg-weak: #2A1A1A;
  --warn: #FBBF24;
  --warn-weak: #2A2113;
  --line: #262A36;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
/* hidden 属性を確実に効かせる（.splash 等の display 指定に負けないように） */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.num { font-family: var(--num); font-feature-settings: "tnum" 1; font-variant-numeric: tabular-nums; }
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 22px 20px 14px; }
.brand .logo { font-weight: 800; font-size: 18px; letter-spacing: -.01em; display: flex; align-items: center; gap: 9px; }
.brand .logo .mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--brand), #8B5CF6); display: grid; place-items: center; color: #fff; font-size: 15px; }
.brand .sub { color: var(--muted); font-size: 12px; margin-top: 3px; margin-left: 35px; }

.nav { padding: 6px 12px; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin: 2px 0; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-weight: 500; font-size: 13.5px;
  transition: background .12s, color .12s;
}
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; stroke-width: 1.9; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--brand-weak); color: var(--brand-strong); font-weight: 600; }
:root[data-theme="dark"] .nav a.active { color: var(--brand-strong); }

.side-foot { padding: 12px; border-top: 1px solid var(--line); }
.side-foot .who { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.side-foot .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-weak); color: var(--brand-strong); display: grid; place-items: center; font-weight: 700; }
.side-foot .who b { font-size: 13px; }
.side-foot .who span { color: var(--muted); font-size: 11px; }
.side-foot .row { display: flex; gap: 8px; margin-top: 8px; }
.side-foot .row button { flex: 1; padding: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; }
.side-foot .row button:hover { background: var(--bg); }

/* ---------- Main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px 4px;
}
.topbar h1 { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.topbar .desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topbar .tools { display: flex; align-items: center; gap: 10px; }
.lang { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.lang button { border: none; background: none; color: var(--muted); font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px; }
.lang button.on { background: var(--brand); color: #fff; }
.period { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13px; font-weight: 600; }
.hamburger { display: none; }

.content { padding: 12px 32px 48px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 22px; }
.card-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-h h2 { font-size: 15px; font-weight: 700; margin: 0; }
.card-h .hint { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 20px; }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 700; color: var(--faint); }

/* ---------- Signature: 収支ヒーロー ---------- */
.hero { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px 28px; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 20px; }
.hero .cash-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.hero .cash { font-family: var(--num); font-size: 46px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; margin-top: 4px; }
.hero .cash small { font-size: 22px; font-weight: 700; color: var(--muted); margin-right: 4px; }
.hero .profit-pill { display: inline-flex; align-items: center; gap: 6px; background: var(--pos-weak); color: var(--pos); font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 999px; }

.flow { display: flex; align-items: stretch; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.flow .seg { flex: 1; min-width: 130px; border-radius: 12px; padding: 14px 16px; border: 1px solid var(--line); }
.flow .seg .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.flow .seg .v { font-family: var(--num); font-size: 21px; font-weight: 800; margin-top: 3px; }
.flow .seg.sales { background: var(--brand-weak); border-color: transparent; }
.flow .seg.sales .v { color: var(--brand-strong); }
.flow .seg.minus .v { color: var(--neg); }
.flow .seg.result { background: var(--pos-weak); border-color: transparent; }
.flow .seg.result .v { color: var(--pos); }
.flow .op { align-self: center; font-size: 22px; font-weight: 800; color: var(--faint); }

.mini { display: flex; gap: 18px; margin-top: 4px; }
.mini .m { flex: 1; }
.mini .m .k { color: var(--muted); font-size: 12px; }
.mini .m .v { font-family: var(--num); font-size: 20px; font-weight: 800; margin-top: 2px; }

/* ---------- Charts ---------- */
.legend { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }
.legend .li { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend .li .amt { margin-left: auto; font-family: var(--num); font-weight: 700; }
.legend .li .pct { color: var(--muted); font-family: var(--num); width: 42px; text-align: right; }
.donut-wrap { display: flex; align-items: center; gap: 22px; }
.donut-center { font-family: var(--num); }

.bars { display: flex; align-items: flex-end; gap: 14px; height: 180px; padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .stack { width: 60%; display: flex; flex-direction: column-reverse; gap: 3px; }
.bars .b-sales { background: var(--brand); border-radius: 4px 4px 0 0; }
.bars .b-cost { background: #C7CBF7; border-radius: 4px 4px 0 0; }
:root[data-theme="dark"] .bars .b-cost { background: #3A3A63; }
.bars .lab { font-size: 11px; color: var(--muted); }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table td { padding: 13px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .r { text-align: right; }
.table .num { font-weight: 600; }
.table-scroll { overflow-x: auto; }

/* ---------- Badges / status ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge.paid, .badge.accepted, .badge.confirmed { background: var(--pos-weak); color: var(--pos); }
.badge.sent, .badge.ordered { background: var(--brand-weak); color: var(--brand-strong); }
.badge.draft { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.overdue, .badge.review { background: var(--neg-weak); color: var(--neg); }
.badge.pending { background: var(--warn-weak); color: var(--warn); }
.badge.rate { background: var(--surface-2); color: var(--muted); font-family: var(--num); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 13px; padding: 9px 15px; border-radius: var(--radius-sm); transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand-strong); }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn.danger { color: var(--neg); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.input, .select, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; font-family: inherit; }
.input:focus, .select:focus, textarea.input:focus { background: var(--surface); border-color: var(--brand); outline: none; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }

/* ---------- Upload / dropzone ---------- */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 34px; text-align: center; color: var(--muted); background: var(--surface-2); transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--brand); background: var(--brand-weak); color: var(--brand-strong); }
.drop .big { font-size: 15px; font-weight: 700; color: var(--ink); margin-top: 10px; }
.drop svg { width: 34px; height: 34px; stroke: var(--brand); }
.drop .btn { margin-top: 14px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 999px; transition: width .2s; }

/* ---------- Receipts gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.rcpt { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.rcpt .thumb { height: 96px; display: grid; place-items: center; color: #fff; font-size: 24px; }
.rcpt .meta { padding: 10px 12px; }
.rcpt .meta .t { font-size: 12.5px; font-weight: 600; line-height: 1.3; }
.rcpt .meta .a { font-family: var(--num); font-weight: 800; margin-top: 4px; }

/* ---------- Kanban (受発注) ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kcol { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.kcol h3 { font-size: 12px; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; margin-bottom: 9px; }
.kcard .co { font-weight: 700; font-size: 13px; }
.kcard .no { color: var(--muted); font-size: 11px; }
.kcard .amt { font-family: var(--num); font-weight: 800; margin-top: 6px; }

/* ---------- Doc preview (見積/請求/申告) — A4縦 ---------- */
.doc-scroll { display: flex; justify-content: center; background: var(--surface-2); padding: 20px; border-radius: 10px; overflow: auto; }
.doc {
  background: #fff; color: #1a1d29; border: 1px solid var(--line); border-radius: 2px;
  /* A4縦（210:297）。画面では幅720px相当で表示 */
  width: 720px; min-height: 1018px; padding: 52px 48px; box-sizing: border-box;
  box-shadow: 0 4px 24px rgba(16,24,40,.14); margin: 0 auto;
}
@media (max-width: 820px) { .doc { width: 100%; min-height: 0; padding: 28px 22px; } .doc-scroll { padding: 0; background: transparent; } }
.doc h2 { text-align: center; letter-spacing: .3em; font-size: 22px; margin: 0 0 24px; }
.doc .head { display: flex; justify-content: space-between; gap: 20px; }
.doc .to { font-size: 15px; font-weight: 700; border-bottom: 2px solid #1a1d29; padding-bottom: 4px; margin-bottom: 14px; }
.doc .from { font-size: 12px; text-align: right; color: #444; line-height: 1.7; }
.doc .amount-box { border: 2px solid #1a1d29; padding: 10px 16px; margin: 18px 0; display: flex; justify-content: space-between; align-items: center; }
.doc .amount-box .num { font-family: var(--num); font-size: 24px; font-weight: 800; }
.doc table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 13px; }
.doc table th { background: #f3f3f6; border: 1px solid #ddd; padding: 8px; font-size: 11px; }
.doc table td { border: 1px solid #ddd; padding: 8px; }
.doc table td.num, .doc table th.num { text-align: right; font-family: var(--num); }
.doc .taxbox { margin-left: auto; width: 260px; font-size: 12px; }
.doc .taxbox div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed #ccc; }
.doc .taxbox .total { font-weight: 800; font-size: 15px; border-bottom: 2px solid #1a1d29; }
.doc .reg { font-size: 11px; color: #555; margin-top: 8px; }
.doc .stamp { display: inline-block; border: 2px solid #d33; color: #d33; border-radius: 50%; width: 54px; height: 54px; text-align: center; line-height: 1.15; font-size: 10px; padding-top: 12px; transform: rotate(-8deg); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(16,20,32,.5); display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-h h2 { font-size: 16px; margin: 0; }
.modal-h .x { border: none; background: none; color: var(--muted); font-size: 22px; line-height: 1; }
.modal-b { padding: 22px; }
.modal-f { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Misc ---------- */
.stat { display: flex; flex-direction: column; gap: 3px; }
.stat .k { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat .v { font-family: var(--num); font-size: 26px; font-weight: 800; }
.stat .d { font-size: 12px; font-weight: 700; }
.d.up { color: var(--pos); } .d.down { color: var(--neg); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.tabs { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-sm); margin-bottom: 18px; }
.tabs button { border: none; background: none; color: var(--muted); font-weight: 600; font-size: 13px; padding: 7px 14px; border-radius: 8px; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.spacer { height: 20px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 10px; font-weight: 600; font-size: 13px; opacity: 0; transition: all .25s; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 260px; transform: translateX(-100%); transition: transform .22s; }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; }
  .topbar { padding: 16px; }
  .content { padding: 8px 16px 48px; }
  .g-2, .g-3, .row3, .kanban { grid-template-columns: 1fr; }
  .hero .cash { font-size: 38px; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 39; display: none; }
  .scrim.show { display: block; }
}

/* ---------- Data table (検索/ソート/ページング) ---------- */
.dt-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.dt-pager { display: flex; align-items: center; gap: 4px; margin-top: 14px; flex-wrap: wrap; }
.dt-pg { min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; font-size: 13px; font-weight: 600; }
.dt-pg:hover:not(:disabled) { background: var(--surface-2); }
.dt-pg.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.dt-pg:disabled { opacity: .4; cursor: default; }
.table th[data-dt-sort]:hover { color: var(--brand-strong); }

/* ---------- Login / splash ---------- */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 80; }
.spin { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.login-screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); z-index: 70; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(16,24,40,.08); padding: 32px; width: 100%; max-width: 380px; }
.login-card .mark { width: 30px; height: 30px; }
.login-card.sent { text-align: center; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .spin { animation: spin 1.2s linear infinite; }
}

/* ---------- 印刷（PDF出力）：帳票だけをA4で ---------- */
@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  #modalBg, #modalBg * { visibility: visible; }
  #modalBg { position: absolute; inset: 0; background: #fff; display: block; padding: 0; overflow: visible; }
  .modal, .modal.wide { max-width: none; width: auto; box-shadow: none; }
  .modal-h, .modal-f { display: none !important; }
  .modal-b { padding: 0; }
  .doc-scroll { padding: 0; background: #fff; overflow: visible; }
  .doc { width: 100%; min-height: auto; border: none; box-shadow: none; padding: 0; }
  @page { size: A4 portrait; margin: 14mm; }
}
