:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --weekend: #fefce8;
  --today-bg: #eff6ff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.header-inner { max-width: 1380px; margin: 0 auto; padding: 10px 14px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-badge { background: var(--primary); color: #fff; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 15px; }

nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab-btn { border: 1px solid transparent; background: transparent; padding: 7px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; transition: 0.15s; }
.tab-btn:hover { background: var(--surface-2); color: var(--text); }
.tab-btn.active { background: var(--primary-soft); color: var(--primary); border-color: #bfdbfe; }

.backup-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
main { max-width: 1380px; margin: 14px auto 60px; padding: 0 14px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-title { font-size: 16px; font-weight: 700; margin: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.stat-value { font-size: 20px; font-weight: 800; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: 0.15s; }
.btn:hover { background: var(--surface-2); }
.btn.active-seg { background: var(--primary-soft); color: var(--primary); border-color: #93c5fd; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #1d4ed8; }
.btn-green { background: var(--green); color: #fff; border-color: var(--green); }
.btn-green:hover { background: #047857; }
.btn-danger { color: var(--red); border-color: #fecaca; background: var(--red-soft); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 9px; font-size: 12px; border-radius: 6px; }

input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
label.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

.progress-track { width: 100%; height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; display: flex; }
.progress-fill { height: 100%; transition: width 0.25s; }
.bg-green { background: var(--green); }
.bg-amber { background: var(--amber); }
.bg-blue { background: var(--primary); }
.bg-red { background: var(--red); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: var(--purple-soft); color: var(--purple); }

.row-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: #fff; flex-wrap: wrap; }
.row-item.is-done { border-left: 4px solid var(--green); }
.row-item.is-plan { border-left: 4px solid var(--amber); background: #fffdf7; }

.quick-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); padding: 4px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; }
.chip:hover { background: var(--primary-soft); border-color: #bfdbfe; color: var(--primary); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 9px; border-bottom: 1px solid var(--border); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 700; background: var(--surface-2); }
tr.highlight-row { background: var(--primary-soft); font-weight: 700; }

.matrix-wrap { overflow: auto; max-height: 74vh; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
table.matrix-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 12px; }
table.matrix-table th, table.matrix-table td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 6px 7px; vertical-align: middle; }
table.matrix-table thead th { position: sticky; top: 0; z-index: 4; background: var(--surface-2); text-align: center; min-width: 78px; text-transform: none; letter-spacing: 0; }
table.matrix-table th.col-proj, table.matrix-table td.col-proj { position: sticky; left: 0; z-index: 3; background: #fff; min-width: 195px; max-width: 225px; text-align: left; box-shadow: 2px 0 4px rgba(15, 23, 42, 0.04); }
table.matrix-table thead th.col-proj { z-index: 6; background: var(--surface-2); }
table.matrix-table th.col-stat, table.matrix-table td.col-stat { position: sticky; left: 195px; z-index: 3; background: #fff; min-width: 110px; text-align: right; box-shadow: 3px 0 6px rgba(15, 23, 42, 0.06); }
table.matrix-table thead th.col-stat { z-index: 6; background: var(--surface-2); }
table.matrix-table tr.summary-row td { background: #f8fafc; font-weight: 700; text-align: center; }
table.matrix-table tr.summary-row td.col-proj, table.matrix-table tr.summary-row td.col-stat { background: #f1f5f9; text-align: left; }
table.matrix-table tr.summary-row td.col-stat { text-align: right; }
table.matrix-table th.is-weekend, table.matrix-table td.is-weekend { background: var(--weekend); }
table.matrix-table th.is-today, table.matrix-table td.is-today { background: var(--today-bg); box-shadow: inset 0 0 0 1px #93c5fd; }
table.matrix-table td.matrix-cell { text-align: center; cursor: pointer; min-width: 78px; height: 46px; transition: background 0.1s; }
table.matrix-table td.matrix-cell:hover { background: #e0f2fe !important; outline: 2px solid var(--primary); outline-offset: -2px; }
.proj-link { cursor: pointer; color: var(--text); }
.proj-link:hover { color: var(--primary); text-decoration: underline; }

.cell-pill { display: inline-block; padding: 1px 5px; border-radius: 5px; font-weight: 700; font-size: 11px; line-height: 1.3; margin: 1px; }
.pill-done { background: var(--green-soft); color: var(--green); border: 1px solid #a7f3d0; }
.pill-plan { background: var(--amber-soft); color: var(--amber); border: 1px solid #fde68a; }
.cell-money { font-size: 10px; font-weight: 700; margin-top: 1px; }

@media (max-width: 700px) {
  table.matrix-table th.col-stat, table.matrix-table td.col-stat { position: static; box-shadow: none; }
  table.matrix-table th.col-proj, table.matrix-table td.col-proj { min-width: 135px; max-width: 150px; }
}

.sim-banner { background: linear-gradient(135deg, #eff6ff 0%, #ecfdf5 100%); border: 1px solid #bfdbfe; border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
input[type="range"] { padding: 0; border: none; box-shadow: none; accent-color: var(--primary); cursor: pointer; }

.actualization-log { border-left: 2px solid var(--border); padding-left: 12px; margin-top: 8px; max-height: 220px; overflow-y: auto; }
.act-entry { margin-bottom: 8px; font-size: 13px; padding: 6px 8px; border-radius: 8px; cursor: pointer; transition: background 0.1s; }
.act-entry:hover { background: var(--surface-2); }
.act-date { font-size: 11px; font-weight: 700; color: var(--primary); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: none; align-items: center; justify-content: center; padding: 14px; z-index: 50; }
.modal-backdrop.open { display: flex; }
.modal-box { background: #fff; border-radius: 14px; max-width: 660px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 18px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15); }

.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 26px; width: 100%; max-width: 360px; box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08); }

.muted { color: var(--muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-primary { color: var(--primary); }
.hidden { display: none !important; }

/* === AI Strategist Tab === */
.ai-wrap { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.ai-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.ai-toolbar-left, .ai-toolbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ai-select { max-width: 210px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border, #cbd5e1); background: var(--card, #fff); font-size: 13px; }
.ai-pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border, #cbd5e1); font-size: 12px; cursor: pointer; user-select: none; background: #f8fafc; }
.ai-pill.on { background: #eff6ff; border-color: #2563eb; color: #1d4ed8; font-weight: 600; }
.ai-pill input { margin: 0; }
.ai-quick-row { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-qbtn { background: #f1f5f9; border-color: #cbd5e1; }
.ai-mem-box { background: #f8fafc; border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 10px; }
.ai-mem-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; font-size: 13px; margin-bottom: 8px; }
.ai-mem-form { display: flex; gap: 6px; margin-bottom: 8px; }
.ai-mem-form input { flex: 1; }
.ai-mem-list { display: flex; flex-direction: column; gap: 4px; }
.ai-mem-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; background: #fff; padding: 5px 8px; border-radius: 6px; border: 1px solid #e2e8f0; }
.ai-feed { height: 54vh; min-height: 300px; max-height: 640px; overflow-y: auto; border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 12px; background: #f8fafc; display: flex; flex-direction: column; gap: 10px; }
.ai-empty { text-align: center; padding: 36px 12px; }
.ai-msg { display: flex; }
.ai-msg-user { justify-content: flex-end; }
.ai-msg-bot { justify-content: flex-start; }
.ai-bubble-user { max-width: 85%; background: #2563eb; color: #fff; padding: 9px 12px; border-radius: 12px 12px 2px 12px; font-size: 14px; line-height: 1.45; }
.ai-bubble-bot { max-width: 94%; background: #fff; border: 1px solid #e2e8f0; padding: 10px 13px; border-radius: 12px 12px 12px 2px; font-size: 14px; line-height: 1.5; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.ai-h2 { font-weight: 700; font-size: 15px; margin: 6px 0 3px; }
.ai-h3 { font-weight: 700; font-size: 14px; margin: 5px 0 2px; }
.ai-li { margin: 2px 0; padding-left: 4px; }
.ai-gap { height: 6px; }
.ai-code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-family: monospace; font-size: 12px; }
.ai-pre { background: #0f172a; color: #e2e8f0; padding: 9px 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; margin: 6px 0; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed #e2e8f0; }
.ai-act-btn { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; font-weight: 600; }
.ai-act-done { display: inline-block; font-size: 12px; color: #15803d; background: #dcfce7; padding: 4px 9px; border-radius: 6px; font-weight: 600; }
.ai-meta { font-size: 11px; color: var(--muted, #64748b); margin-top: 7px; }
.ai-warn { background: #fef3c7; color: #92400e; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.ai-input-row { display: flex; gap: 8px; align-items: stretch; }
.ai-input-row textarea { flex: 1; resize: vertical; min-height: 48px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border, #cbd5e1); font-family: inherit; font-size: 14px; }
.ai-send-btn { min-width: 96px; justify-content: center; }
@media (max-width: 640px) {
  .ai-feed { height: 50vh; padding: 8px; }
  .ai-bubble-bot, .ai-bubble-user { max-width: 98%; font-size: 13.5px; }
  .ai-input-row { flex-direction: column; }
  .ai-send-btn { width: 100%; padding: 10px; }
}

.ai-pill { white-space: nowrap; width: auto; flex-shrink: 0; }
.ai-pill input[type="checkbox"] { width: auto !important; height: auto; margin: 0; flex: 0 0 auto; }
.ai-h1 { font-weight: 800; font-size: 16px; margin: 6px 0 4px; color: #0f172a; }
.ai-hr { border: none; border-top: 1px solid #e2e8f0; margin: 8px 0; }
.ai-tbl-wrap { overflow-x: auto; margin: 6px 0; }
.ai-tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; background: #fff; }
.ai-tbl th, .ai-tbl td { border: 1px solid #e2e8f0; padding: 5px 7px; text-align: left; vertical-align: top; }
.ai-tbl th { background: #f1f5f9; font-weight: 700; }
