/* KAMAE 工程管理アプリ — UIスタイル（kamae-visual の世界観をアプリへ適用）
   ダーク・モノクロ＋amber1点・線・余白・洗練。装飾過多にしない。 */
:root {
  --bg: #1a1a1a;        /* 地 */
  --panel: #1f1f1f;     /* パネル面（僅かに明るい黒） */
  --panel-2: #242424;   /* 二次面 */
  --line: #ececec;      /* 主テキスト */
  --sub: #9a9a9a;       /* 補助 */
  --faint: #6a6a6a;     /* 最薄 */
  --frame: #363636;     /* 枠・罫 */
  --amber: #E8780A;     /* アクセント（1画面の主役だけ） */
  --amber-soft: rgba(232,120,10,.12);
  /* ガント状態色（機能情報・彩度を抑えた“くすみ”配色） */
  --st-todo: #5a5a5a;   /* 未着手=グレー枠 */
  --st-ok:   #6f8fa6;   /* 進行中(順調)=落ち着いた寒色 */
  --st-warn: #E8780A;   /* 進行中(注意)=amber */
  --st-late: #9e4b40;   /* 遅延=くすんだ赤 */
  --st-done: #6f8f73;   /* 完了=落ち着いた緑 */
  --radius: 14px;
  --gap: 16px;
  --serif: Georgia, "Times New Roman", serif;
  --gothic: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--line);
  font-family: var(--gothic);
  font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }

/* ───────── 共通要素 ───────── */
.kicker { font-family: var(--serif); color: var(--sub); letter-spacing: .12em; font-size: 13px; }
.h1 { font-size: 26px; font-weight: 700; margin: 4px 0 0; }
.muted { color: var(--sub); }
.faint { color: var(--faint); }
.amber { color: var(--amber); }
.rule { height: 1px; background: var(--frame); border: 0; margin: 0; }

.btn {
  appearance: none; border: 1px solid var(--frame); background: var(--panel);
  color: var(--line); border-radius: 10px; padding: 11px 16px; font-size: 15px;
  transition: border-color .18s ease, background .18s ease, color .18s ease;
}
.btn:hover { border-color: #4a4a4a; }
.btn-primary {
  background: var(--amber); border-color: var(--amber); color: #1a1a1a; font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.tag {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--frame); color: var(--sub);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ───────── ログイン ───────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; }
.brand-line { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { font-family: var(--serif); letter-spacing: .22em; color: var(--sub); font-size: 14px; }
.brand-amber { width: 26px; height: 2px; background: var(--amber); display: inline-block; }
.login h1 { font-size: 30px; font-weight: 700; margin: 10px 0 2px; }
.login .lead { color: var(--sub); font-size: 14px; margin-bottom: 26px; }

.user-list { display: flex; flex-direction: column; gap: 8px; }
.user-row {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; text-align: left; background: var(--panel);
  border: 1px solid var(--frame); border-radius: 12px; padding: 14px 16px;
  transition: border-color .18s ease;
}
.user-row:hover { border-color: #4a4a4a; }
.user-row .name { font-weight: 600; }
.user-row .role { font-size: 12px; color: var(--sub); }

/* テンキー */
.pin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.pin-back { background: transparent; border: 0; color: var(--sub); font-size: 14px; padding: 4px 0; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 6px 0 22px; }
.pin-dots .pd { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--frame); }
.pin-dots .pd.on { background: var(--amber); border-color: var(--amber); }
.pin-err { color: #c98379; font-size: 13px; min-height: 18px; text-align: center; margin-bottom: 8px; }
.tenkey { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.key {
  aspect-ratio: 1.6 / 1; border: 1px solid var(--frame); background: var(--panel);
  border-radius: 12px; font-size: 24px; font-weight: 600; color: var(--line);
  display: grid; place-items: center; transition: background .12s ease, border-color .12s ease;
}
.key:active { background: var(--panel-2); border-color: #4a4a4a; }
.key.fn { font-size: 15px; color: var(--sub); }

/* ───────── アプリシェル ───────── */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; background: rgba(26,26,26,.86);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--frame);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; padding-top: max(12px, env(safe-area-inset-top));
}
.topbar .left { display: flex; align-items: center; gap: 12px; }
.topbar .mark { font-family: var(--serif); letter-spacing: .2em; color: var(--sub); font-size: 13px; }
.topbar .bar { width: 22px; height: 2px; background: var(--amber); }
.whoami { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--sub); }
.whoami .me { color: var(--line); font-weight: 600; }

.tabs {
  display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--frame);
  overflow-x: auto; scrollbar-width: none; background: var(--bg);
  position: sticky; top: 53px; z-index: 9;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  color: var(--sub); padding: 8px 12px; font-size: 14px; white-space: nowrap;
}
.tab.active { color: var(--line); border-bottom-color: var(--amber); font-weight: 600; }

.content { flex: 1; padding: 20px 18px 40px; max-width: 1100px; width: 100%; margin: 0 auto; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.section-head .ttl { font-size: 20px; font-weight: 700; }
.section-head .amber-underline { width: 120px; height: 2px; background: var(--amber); margin-top: 6px; }

/* 物件カード */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--frame); border-radius: var(--radius);
  padding: 16px 16px 14px; transition: border-color .18s ease;
}
.card:hover { border-color: #4a4a4a; }
.card .cname { font-size: 16px; font-weight: 700; }
.card .ctype { font-size: 12px; color: var(--sub); }
.card .meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* 空状態 / オンボーディング */
.empty {
  border: 1px dashed var(--frame); border-radius: var(--radius);
  padding: 48px 28px; text-align: center; color: var(--sub); background: var(--panel);
}
.empty .icon { display: grid; place-items: center; margin: 0 auto 14px; opacity: .92; }
.empty .icon svg { display: block; }
.empty h3 { color: var(--line); margin: 0 0 6px; font-size: 17px; }
.empty p { margin: 0 auto 18px; max-width: 360px; font-size: 14px; }

/* 状態凡例（一箇所に集約） */
.legend { display: flex; flex-wrap: wrap; gap: 14px; padding: 12px 14px; border: 1px solid var(--frame);
  border-radius: 12px; background: var(--panel); color: var(--sub); font-size: 12.5px; }
.legend .li { display: flex; align-items: center; gap: 7px; }
.sw { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.todo { background: transparent; border: 1.5px solid var(--st-todo); }
.sw.ok   { background: var(--st-ok); }
.sw.warn { background: var(--st-warn); }
.sw.late { background: var(--st-late); }
.sw.done { background: var(--st-done); }

.banner { font-size: 12px; color: var(--faint); border: 1px solid var(--frame); border-radius: 8px;
  padding: 6px 10px; display: inline-block; margin-bottom: 16px; }

@media (max-width: 560px) {
  .content { padding: 16px 14px 36px; }
  .cards { grid-template-columns: 1fr; }
}

/* ───────── Phase 2: 共通 ───────── */
.head-actions { display: flex; gap: 8px; }
.card-btn { text-align: left; width: 100%; font: inherit; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.todayk { width: 2px; height: 12px; background: var(--amber); display: inline-block; border-radius: 2px; }

/* フォーム要素 */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--sub); }
.form input, .form select {
  appearance: none; background: var(--panel-2); color: var(--line);
  border: 1px solid var(--frame); border-radius: 10px; padding: 11px 12px; font-size: 15px; font-family: inherit;
}
.form input:focus, .form select:focus { outline: none; border-color: var(--amber); }
.form input:disabled, .form select:disabled { opacity: .5; }
.form select { background-image: linear-gradient(45deg, transparent 50%, var(--sub) 50%), linear-gradient(135deg, var(--sub) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

/* モーダル */
.modal-ov { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 18px; z-index: 50; }
.modal { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--frame); border-radius: 16px; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--frame); }
.modal-head .mtitle { font-size: 16px; font-weight: 700; }
.modal-head .mx { background: transparent; border: 0; color: var(--sub); font-size: 16px; }
.modal-body { padding: 18px; max-height: 64vh; overflow: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; align-items: center; padding: 14px 18px; border-top: 1px solid var(--frame); }

/* 工程リスト */
.proc-list { margin-top: 16px; border: 1px solid var(--frame); border-radius: 12px; overflow: hidden; }
.proc-row { display: grid; grid-template-columns: 16px 1fr auto auto; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--frame); cursor: pointer; transition: background .15s ease; }
.proc-row:last-child { border-bottom: 0; }
.proc-row:hover { background: var(--panel-2); }
.proc-row .pname { font-weight: 600; }
.proc-row .pdate { font-size: 12px; }
.proc-row .pstat { font-size: 12px; white-space: nowrap; }

/* ───────── ガント ───────── */
.gantt-wrap { margin-top: 14px; }
.period { display: inline-flex; gap: 4px; background: var(--panel); border: 1px solid var(--frame); border-radius: 10px; padding: 4px; margin-bottom: 12px; }
.pbtn { background: transparent; border: 0; color: var(--sub); padding: 6px 14px; border-radius: 7px; font-size: 13px; }
.pbtn.active { background: var(--panel-2); color: var(--line); font-weight: 600; }
.gantt { position: relative; border: 1px solid var(--frame); border-radius: 12px; overflow: auto; background: var(--panel); }
.g-head { display: grid; border-bottom: 1px solid var(--frame); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.g-corner { border-right: 1px solid var(--frame); }
.g-axis { display: flex; }
.g-day { box-sizing: border-box; text-align: center; padding: 6px 0 5px; font-size: 11px; color: var(--sub); border-right: 1px solid rgba(54,54,54,.5); position: relative; }
.g-day .mon { position: absolute; top: 6px; left: 4px; color: var(--faint); font-size: 10px; white-space: nowrap; }
.g-day .dd { display: block; margin-top: 10px; }
.g-day.we { color: var(--faint); }
.g-day.td .dd { color: var(--amber); font-weight: 700; }
.g-body { position: relative; }
.g-row { display: grid; border-bottom: 1px solid rgba(54,54,54,.5); }
.g-row:last-child { border-bottom: 0; }
.g-label { box-sizing: border-box; padding: 10px 12px; border-right: 1px solid var(--frame); display: flex; flex-direction: column; justify-content: center; }
.g-label.clickable { cursor: pointer; }
.g-label.clickable:hover { background: var(--panel-2); }
.gl-name { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.gl-sub { font-size: 11px; }
.g-lane { position: relative; height: 44px; }
.we-shade { position: absolute; top: 0; bottom: 0; background: rgba(255,255,255,.02); }
.g-bar { position: absolute; top: 11px; height: 22px; border-radius: 6px; overflow: hidden; }
.g-bar.clickable { cursor: pointer; }
.g-bar.todo { background: transparent; border: 1.5px solid var(--st-todo); }
.g-bar.ok   { background: var(--st-ok); }
.g-bar.warn { background: var(--st-warn); }
.g-bar.late { background: var(--st-late); }
.g-bar.done { background: var(--st-done); }
.g-prog { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(0,0,0,.25); }
.today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--amber); opacity: .9; pointer-events: none; }

@media (max-width: 560px) {
  .row2 { grid-template-columns: 1fr; }
  .proc-row { grid-template-columns: 14px 1fr auto; }
  .proc-row .pdate { display: none; }
}

/* ───────── ガント：週/月 粒度の目盛り ───────── */
.g-axis.week, .g-axis.month { display: block; position: relative; height: 30px; }
.g-tick { position: absolute; top: 0; bottom: 0; border-left: 1px solid rgba(54,54,54,.55); padding-top: 9px; }
.g-tick.major { border-left-color: var(--frame); }
.g-tick span { display: inline-block; padding-left: 4px; font-size: 11px; color: var(--sub); white-space: nowrap; }
.g-tick.major span { color: var(--line); }
.grid-line { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(54,54,54,.30); }
.grid-line.major { background: var(--frame); }

/* ───────── 印刷（@media print）：横向き・白地反転・操作UI非表示・状態色維持 ───────── */
@media print {
  @page { size: landscape; margin: 10mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { background: #ffffff !important; color: #1a1a1a !important; }

  /* 操作UIは隠す（ナビ・タブ・各種ボタン・バナー・期間切替・モーダル） */
  .topbar, .tabs, .head-actions, .banner, .period, .no-print,
  .modal-ov, .pin-back, .btn { display: none !important; }

  /* レイアウトを用紙いっぱいに */
  .content { max-width: none !important; padding: 0 !important; margin: 0 !important; }
  .section-head { margin-bottom: 10px; }
  .gantt-wrap, .proc-list, .legend, .card { break-inside: avoid; }

  /* 白地テーマ：面・枠・文字 */
  .card, .legend, .proc-list, .gantt, .g-head, .modal { background: #ffffff !important; border-color: #b9b9b9 !important; }
  .proc-row, .g-row, .g-label, .g-corner, .g-day { border-color: #cccccc !important; }
  .ttl, .gl-name, .pname, .cname, .mtitle { color: #1a1a1a !important; }
  .kicker, .gl-sub, .faint, .muted, .ctype, .g-day, .g-tick span, .pdate, .pstat { color: #555555 !important; }
  .tag { color: #333333 !important; border-color: #b9b9b9 !important; background: #fff !important; }
  .amber-underline { background: #E8780A !important; }

  /* ガント：全幅を出す（横切れ防止）。zoomはJSが用紙幅に合わせて付与 */
  .gantt { overflow: visible !important; }
  .g-head { position: static !important; }
  .g-day.td .dd { color: #C8620A !important; }
  .we-shade { background: rgba(0,0,0,.05) !important; }
  .grid-line { background: #e3e3e3 !important; }
  .grid-line.major { background: #c2c2c2 !important; }
  .g-prog { background: rgba(0,0,0,.18) !important; }
  .today-line { background: #E8780A !important; opacity: 1 !important; }

  /* 状態色：白地でも識別できる濃さを保持 */
  .g-bar.todo { background: transparent !important; border-color: #777777 !important; }
  .g-bar.ok   { background: #4f7da0 !important; }
  .g-bar.warn { background: #E8780A !important; }
  .g-bar.late { background: #b4453a !important; }
  .g-bar.done { background: #5f8f6a !important; }
  .sw.todo { border-color: #777777 !important; }
  .sw.ok   { background: #4f7da0 !important; }
  .sw.warn { background: #E8780A !important; }
  .sw.late { background: #b4453a !important; }
  .sw.done { background: #5f8f6a !important; }
}

/* ───────── 工程の取込（CSV / 画像AI）プレビュー ───────── */
.modal-wide { max-width: 760px; }
.imp-note { font-size: 12.5px; color: var(--sub); line-height: 1.7; margin-bottom: 14px; }
.imp-note b { color: var(--line); font-weight: 600; }
.lnk { color: var(--amber); text-decoration: none; border-bottom: 1px solid rgba(232,120,10,.5); }
.imp-count { color: var(--faint); }
.form textarea {
  appearance: none; background: var(--panel-2); color: var(--line); border: 1px solid var(--frame);
  border-radius: 10px; padding: 11px 12px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical;
}
.form textarea:focus { outline: none; border-color: var(--amber); }
.imp-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--frame); border-radius: 10px; }
.imp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.imp-table th { position: sticky; top: 0; background: var(--panel-2); color: var(--sub); font-weight: 600;
  text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--frame); font-size: 12px; }
.imp-table td { padding: 5px 6px; border-bottom: 1px solid rgba(54,54,54,.5); }
.imp-table tr.err td { background: rgba(158,75,64,.16); }
.imp-table .ic { width: 100%; background: var(--panel); color: var(--line); border: 1px solid var(--frame);
  border-radius: 7px; padding: 7px 8px; font-size: 13px; font-family: inherit; }
.imp-table .ic.dt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.imp-table tr.err .ic { border-color: #9e4b40; }
.imp-table .ic:focus { outline: none; border-color: var(--amber); }
.imp-table .rm { background: transparent; border: 1px solid var(--frame); color: var(--sub); border-radius: 7px; width: 30px; height: 30px; }
.imp-table .rm:hover { border-color: #9e4b40; color: #c98379; }
.imp-err { color: #c98379; font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* ───────── Phase 4: 設定（業者/ユーザー） ───────── */
.set-list { border: 1px solid var(--frame); border-radius: 12px; overflow: hidden; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--frame); }
.set-row:last-child { border-bottom: 0; }
.set-row .sr-name { font-weight: 600; }
.set-row .sr-actions { margin-left: auto; display: flex; gap: 8px; }
.set-row .sr-actions .btn { padding: 7px 12px; font-size: 13px; }
.sw-color { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(255,255,255,.15); flex: 0 0 auto; }
.flbl { font-size: 13px; color: var(--sub); margin-bottom: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 8px; border: 2px solid transparent; }
.swatch.on { border-color: var(--line); box-shadow: 0 0 0 2px var(--bg) inset; }

/* ───────── Phase 4: 物件写真 ───────── */
.photo-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.photo-cell { position: relative; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--frame); background: var(--panel-2); }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.ph-del { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 7px;
  background: rgba(0,0,0,.55); border: 1px solid var(--frame); color: #fff; font-size: 13px; line-height: 1; }
.ph-del:hover { background: rgba(158,75,64,.85); border-color: #9e4b40; }
.lb-ov { position: fixed; inset: 0; background: rgba(0,0,0,.82); display: grid; place-items: center; z-index: 60; padding: 24px; cursor: zoom-out; }
.lb-ov img { max-width: 94vw; max-height: 90vh; border-radius: 8px; }
.lb-x { position: fixed; top: 16px; right: 18px; background: transparent; border: 0; color: #fff; font-size: 20px; }

@media print {
  .set-list, .swatches, .photo-grid .ph-del, .lb-ov { display: none !important; }
}

/* ───────── Phase 5: トースト / ローディング / 印刷ヘッダ ───────── */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 80; pointer-events: none; }
.toast-item { background: var(--panel); border: 1px solid var(--frame); color: var(--line);
  border-radius: 10px; padding: 11px 18px; font-size: 13.5px; box-shadow: 0 6px 24px rgba(0,0,0,.4);
  opacity: 1; transition: opacity .28s ease, transform .28s ease; }
.toast-item.err { border-color: #9e4b40; color: #e0a59c; }
.toast-item.out { opacity: 0; transform: translateY(8px); }

.loadbar { position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--amber);
  z-index: 90; opacity: 0; transition: width .2s ease, opacity .2s ease; }
body.busy .loadbar { width: 80%; opacity: 1; }

.print-head { display: none; }

@media print {
  /* 印刷ヘッダ（物件名・出力日） */
  .print-head { display: block !important; margin: 0 0 10px; padding-bottom: 8px; border-bottom: 1px solid #bbb; }
  .print-head .ph-mark { font-family: var(--serif); letter-spacing: .12em; color: #777; font-size: 11px; margin-right: 12px; }
  .print-head .ph-title { font-size: 18px; font-weight: 700; color: #1a1a1a; }
  .print-head .ph-meta { display: block; margin-top: 3px; font-size: 11px; color: #666; }
  /* 写真セクションはPDFから除外（スケジュール1枚に集約／写真は画面閲覧向き） */
  .photos-sec { display: none !important; }
  .toast, .loadbar { display: none !important; }
}

@media (max-width: 560px) {
  .set-row { flex-wrap: wrap; }
  .set-row .sr-actions { margin-left: 0; width: 100%; }
  .modal-wide { max-width: 100%; }
}
