:root {
  --ink: #0f172a; --muted: #64748b; --line: #e2e8f0; --line2: #f1f5f9;
  --panel: #ffffff; --page: #f8fafc; --accent: #0f172a;
  --blue: #2563eb; --green: #059669; --amber: #d97706; --red: #e11d48;
  --sb-w: 240px; --sb-r: 280px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Inter, system-ui, sans-serif; background: var(--page); color: var(--ink); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }

/* ── SVG Icons ── */
.ic { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.ic-xs { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(2px); }
.modal { background: var(--panel); border-radius: 12px; width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 80px rgba(0,0,0,0.15); border: 1px solid var(--line); }
.modal-wide { width: 760px; }
.modal-header { padding: 28px 28px 0; }
.modal-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--line2); display: grid; place-items: center; color: var(--ink); margin-bottom: 16px; }
.modal-header h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.modal-header p { font-size: 13px; color: var(--muted); margin-top: 4px; }
.modal-body { padding: 20px 28px; }
.modal-footer { padding: 0 28px 24px; display: flex; justify-content: flex-end; }

/* ── Forms ── */
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.form-group input, .form-group select { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; background: var(--panel); transition: border-color 0.15s; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--ink); }
.hint { font-size: 11px; color: var(--muted); }

/* Segmented control */
.seg-group { display: flex; background: var(--line2); border-radius: 8px; padding: 3px; gap: 2px; }
.seg { flex: 1; text-align: center; cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; padding: 7px 10px; font-size: 13px; font-weight: 500; border-radius: 6px; transition: all 0.15s; color: var(--muted); }
.seg input:checked + span { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

/* ── Buttons ── */
.btn-primary { display: inline-flex; align-items: center; gap: 6px; background: var(--ink); color: #fff; border: none; padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; transition: background 0.15s; }
.btn-primary:hover { background: #1e293b; }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 1px solid var(--line); padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit; color: var(--ink); transition: all 0.15s; }
.btn-ghost:hover { background: var(--line2); }
.btn-icon { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; color: var(--muted); transition: all 0.15s; }
.btn-icon:hover { color: var(--ink); background: var(--line2); }
.btn-icon-xs { display: inline-grid; place-items: center; width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer; color: var(--muted); transition: all 0.15s; flex-shrink: 0; }
.btn-icon-xs:hover { color: var(--ink); background: var(--line2); }
.btn-text-xs { display: inline-flex; align-items: center; gap: 4px; background: none; border: none; padding: 4px 0; font-size: 12px; font-weight: 500; color: var(--muted); cursor: pointer; font-family: inherit; }
.btn-text-xs:hover { color: var(--ink); }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); gap: 12px; height: 52px; }
.toolbar-left { display: flex; align-items: center; gap: 8px; }
.app-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; color: var(--ink); }
.toolbar-center { flex: 1; display: flex; justify-content: center; }
.title-input { border: 1px solid transparent; background: transparent; font-size: 14px; font-weight: 600; text-align: center; padding: 6px 12px; border-radius: 6px; font-family: inherit; width: 280px; }
.title-input:hover, .title-input:focus { border-color: var(--line); background: var(--line2); outline: none; }
.toolbar-right { display: flex; align-items: center; gap: 6px; }

/* ── Dropdown ── */
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: 100%; margin-top: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.08); padding: 4px; min-width: 100px; z-index: 50; }
.dropdown-menu button { display: flex; width: 100%; align-items: center; padding: 7px 12px; border: none; background: none; font-size: 13px; font-weight: 500; cursor: pointer; border-radius: 6px; font-family: inherit; color: var(--ink); }
.dropdown-menu button:hover { background: var(--line2); }

/* ── Editor Body ── */
.editor-body { display: flex; height: calc(100vh - 52px); overflow: hidden; }

/* ── Sidebars ── */
.sidebar-left, .sidebar-right { flex-shrink: 0; background: var(--panel); overflow: visible; transition: width 0.2s ease; display: flex; flex-direction: column; position: relative; }
.sidebar-left { width: var(--sb-w); border-right: 1px solid var(--line); }
.sidebar-right { width: var(--sb-r); border-left: 1px solid var(--line); }
.sidebar-left.collapsed { width: 0; }
.sidebar-right.collapsed { width: 0; }
.sidebar-inner { width: var(--sb-w); overflow-y: auto; overflow-x: hidden; height: 100%; }
.sidebar-right .sidebar-inner { width: var(--sb-r); }
.sidebar-left.collapsed .sidebar-inner { display: none; }
.sidebar-right.collapsed .sidebar-inner { display: none; }

/* Toggle button */
.sb-toggle { position: absolute; top: 50%; transform: translateY(-50%); width: 20px; height: 40px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); cursor: pointer; display: grid; place-items: center; color: var(--muted); z-index: 20; transition: all 0.2s; }
.sb-toggle:hover { background: var(--line2); color: var(--ink); }
.sidebar-left .sb-toggle { right: -10px; }
.sidebar-right .sb-toggle { left: -10px; }
.sidebar-left.collapsed .sb-toggle, .sidebar-right.collapsed .sb-toggle { background: var(--ink); color: #fff; border-color: var(--ink); }
.sidebar-left.collapsed .sb-toggle { right: -20px; }
.sidebar-right.collapsed .sb-toggle { left: -20px; }

/* ── Preview ── */
.preview-area { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.preview-toolbar { display: flex; align-items: center; gap: 4px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-shrink: 0; }
.ctrl-group { display: flex; align-items: center; gap: 2px; }
.ctrl-label { font-size: 11px; color: var(--muted); font-weight: 600; margin-right: 4px; }
.ctrl-val { font-size: 12px; font-weight: 600; min-width: 32px; text-align: center; color: var(--ink); }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.svg-container { flex: 1; padding: 20px; overflow: auto; display: flex; justify-content: center; align-items: flex-start; background: var(--page); }
.svg-container svg { box-shadow: 0 1px 3px rgba(0,0,0,0.06); border-radius: 6px; max-width: none; background: #fff; }

/* ── Sidebar headers ── */
.sidebar-header { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 6px; }
.sidebar-header h3 { font-size: 12px; font-weight: 700; flex: 1; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.sidebar-section { padding: 12px 14px; border-top: 1px solid var(--line); }
.sidebar-section h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 8px; }

/* ── Rows list ── */
.rows-list { padding: 6px; }
.row-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px; cursor: pointer; margin-bottom: 2px; border: 1px solid transparent; }
.row-item:hover { background: var(--line2); }
.row-item.selected { border-color: var(--ink); background: var(--line2); }
.row-item .row-label { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .row-cat { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.row-item .row-del { opacity: 0; color: var(--red); cursor: pointer; flex-shrink: 0; display: flex; }
.row-item:hover .row-del { opacity: 0.5; }
.row-item .row-del:hover { opacity: 1; }
.row-item.phase { background: var(--line2); font-weight: 700; border-radius: 6px; }
.row-item.phase .row-cat { display: none; }
.row-dur { font-size: 10px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; flex-shrink: 0; font-weight: 600; }

/* ── Categories ── */
.categories-list { margin-bottom: 8px; }
.cat-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; margin-bottom: 2px; }
.cat-item:hover { background: var(--line2); }
.cat-item .cat-color { width: 18px; height: 18px; border-radius: 4px; cursor: pointer; border: 1px solid var(--line); }
.cat-item .cat-label { flex: 1; font-size: 13px; border: none; background: transparent; font-family: inherit; }
.cat-item .cat-label:focus { outline: none; }
.cat-item .cat-del { color: var(--red); cursor: pointer; opacity: 0.4; display: flex; }
.cat-item .cat-del:hover { opacity: 1; }

/* ── Properties ── */
.properties-panel { padding: 14px; }
.prop-group { margin-bottom: 12px; }
.prop-group label { display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.prop-group input, .prop-group select { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; font-family: inherit; background: var(--panel); }
.prop-group input:focus, .prop-group select:focus { outline: none; border-color: var(--ink); }
.cell-list { margin-bottom: 8px; }
.cell-item { border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin-bottom: 6px; }
.cell-item .cell-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cell-item .cell-header span { font-size: 12px; font-weight: 600; color: var(--muted); }
.color-input { width: 36px; height: 30px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; padding: 2px; }

/* Row duration box */
.row-dur-box { background: var(--line2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.row-dur-row { display: flex; gap: 10px; }
.row-dur-row > div { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.dur-mini-label { font-size: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.dur-mini-input { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 15px; font-weight: 700; text-align: center; font-family: inherit; background: var(--panel); }
.dur-mini-input:focus { outline: none; border-color: var(--ink); }
.dur-mini-val { font-size: 15px; font-weight: 700; padding: 8px 0; text-align: center; color: var(--ink); }

/* ── Holidays ── */
.holiday-item { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 3px 0; }
.holiday-item .hol-del { color: var(--red); cursor: pointer; opacity: 0.4; display: flex; }
.holiday-item .hol-del:hover { opacity: 1; }
.inline-form { display: flex; gap: 4px; margin-top: 8px; align-items: center; }
.input-sm { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; font-family: inherit; background: var(--panel); }
.input-sm:focus { outline: none; border-color: var(--ink); }
.input-sm[type="date"] { width: 124px; }
.input-sm[type="text"] { flex: 1; }

/* ── JSON Modal ── */
.json-actions { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.json-textarea { width: 100%; height: 380px; font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; background: var(--line2); }

@media (max-width: 900px) {
  .sidebar-left, .sidebar-left .sidebar-inner { width: 180px; }
  .sidebar-right, .sidebar-right .sidebar-inner { width: 180px; }
  .title-input { width: 120px; }
}
