@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,700&family=JetBrains+Mono:wght@400;600&display=swap");

:root {
  --bg: #eee5d7;
  --card: rgba(250, 245, 238, 0.94);
  --card-2: rgba(244, 236, 225, 0.92);
  --input: rgba(255, 252, 248, 0.94);
  --border: rgba(84, 61, 28, 0.16);
  --border-strong: rgba(84, 61, 28, 0.26);
  --text: #261b12;
  --muted: #6f6258;
  --dim: #8c7b6b;
  --accent: #c55c1f;
  --accent-secondary: #8e3f12;
  --accent-soft: rgba(197, 92, 31, 0.1);
  --green: #16845b;
  --amber: #b7791f;
  --red: #b42318;
  --radius: 16px;
  --shadow: 0 12px 30px rgba(77, 50, 20, 0.05);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "DM Sans", sans-serif;
  font-size: 14px;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.46; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: rgba(84, 61, 28, 0.06); }
::-webkit-scrollbar-thumb { background: rgba(84, 61, 28, 0.22); border-radius: 999px; }

.main-content { width: 100%; min-height: 100vh; padding: 20px 28px 52px; }
.topbar { display: flex; align-items: center; gap: 14px; min-height: 44px; }
.hub-button {
  display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto;
  padding: 10px 20px; border: 1px solid rgba(197, 92, 31, 0.52); border-radius: 8px;
  color: var(--accent); background: linear-gradient(135deg, #efc89f, #faefe1);
  box-shadow: 0 2px 8px rgba(197, 92, 31, 0.1); font-size: 13px; font-weight: 700;
}
.hub-button span { font-size: 18px; line-height: 1; }
.topbar-context { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 12px; }
.topbar-context b { color: rgba(84, 61, 28, 0.3); font-weight: 400; }
.topbar-context strong { color: var(--text); }
.topbar-actions, .timeline-actions, .table-actions, .legend-items { display: flex; align-items: center; gap: 10px; }
.topbar-actions { margin-left: auto; }

.ghost-button, .primary-button, .danger-button, .icon-button, .text-button {
  border-radius: 8px; transition: 0.16s ease; font-weight: 700;
}
.ghost-button { padding: 9px 13px; color: var(--muted); background: var(--input); border: 1px solid var(--border); font-size: 12px; }
.ghost-button:hover { border-color: var(--border-strong); background: #fffaf4; }
.primary-button { display: inline-flex; align-items: center; gap: 5px; padding: 10px 15px; border: 1px solid var(--accent); color: #fffaf5; background: var(--accent); box-shadow: 0 5px 14px rgba(197, 92, 31, 0.18); font-size: 12px; }
.primary-button:hover { background: var(--accent-secondary); border-color: var(--accent-secondary); transform: translateY(-1px); }
.danger-button { padding: 8px 11px; color: var(--red); background: rgba(180, 35, 24, 0.08); border: 1px solid rgba(180, 35, 24, 0.18); font-size: 10px; }
.text-button { padding: 5px 0; color: var(--accent); background: transparent; border: 0; font-size: 11px; }
.text-button:hover { color: var(--accent-secondary); }
.icon-button { display: grid; place-items: center; width: 31px; height: 31px; color: var(--muted); background: var(--input); border: 1px solid var(--border); }
.icon-button:hover { color: var(--accent); border-color: rgba(197, 92, 31, 0.32); }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 34px 0 24px; }
.section-kicker, .panel-kicker, .modal-kicker { color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 0.12em; }
h1 { margin-top: 7px; font-size: clamp(29px, 3vw, 38px); line-height: 1; letter-spacing: -0.045em; }
.page-heading p { max-width: 760px; margin-top: 10px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.heading-note { display: flex; align-items: center; gap: 9px; padding: 10px 13px; border: 1px solid var(--border); border-radius: 10px; color: var(--muted); background: var(--card); font-size: 10px; line-height: 1.4; }
.heading-note b { color: var(--text); }
.note-icon { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid rgba(197, 92, 31, 0.36); border-radius: 50%; color: var(--accent); font-weight: 800; }
.heading-note[data-state="synced"] .note-icon { color: var(--green); border-color: rgba(22, 132, 91, 0.36); }
.heading-note[data-state="offline"] .note-icon { color: var(--red); border-color: rgba(180, 35, 24, 0.36); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric-card { display: flex; align-items: center; gap: 11px; min-height: 84px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-2); }
.metric-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; font-size: 17px; font-weight: 700; }
.metric-icon.orange { color: var(--accent); background: var(--accent-soft); }
.metric-icon.green { color: var(--green); background: rgba(22, 132, 91, 0.1); }
.metric-icon.amber { color: var(--amber); background: rgba(183, 121, 31, 0.1); }
.metric-icon.brown { color: #775640; background: rgba(119, 86, 64, 0.1); }
.metric-label { display: block; color: var(--dim); font-size: 9px; font-weight: 800; letter-spacing: 0.1em; }
.metric-card strong { display: block; margin-top: 4px; font-size: 23px; line-height: 1; letter-spacing: -0.04em; }
.metric-trend { margin-left: auto; align-self: flex-start; padding: 5px 7px; border-radius: 999px; color: var(--dim); background: rgba(84, 61, 28, 0.07); font-size: 9px; font-weight: 700; text-transform: uppercase; }
.metric-trend.positive { color: var(--green); background: rgba(22, 132, 91, 0.1); }

.panel { margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); overflow: hidden; }
.filter-panel { position: relative; z-index: 10; overflow: visible; }
.filter-panel .filter-dropdown[open] { z-index: 30; }
.filter-panel .filter-options { z-index: 40; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.panel-header.compact { padding: 17px 20px; }
.panel-kicker { display: block; font-size: 9px; }
h2 { margin-top: 4px; font-size: 17px; letter-spacing: -0.025em; }

.filter-grid { display: grid; grid-template-columns: 1.1fr 1.1fr 1fr 1.5fr; gap: 12px; padding: 18px 20px 14px; }
.filter-field label, .form-row label, form > label { display: block; color: var(--dim); font-size: 10px; font-weight: 800; letter-spacing: 0.08em; }
.filter-dropdown { position: relative; margin-top: 7px; }
.filter-dropdown summary { display: flex; align-items: center; justify-content: space-between; min-height: 39px; padding: 0 11px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); background: var(--input); cursor: pointer; list-style: none; font-size: 12px; }
.filter-dropdown summary::-webkit-details-marker { display: none; }
.filter-dropdown[open] summary { border-color: rgba(197, 92, 31, 0.42); box-shadow: 0 0 0 3px var(--accent-soft); }
.filter-options { position: absolute; z-index: 20; top: calc(100% + 5px); left: 0; right: 0; min-width: 190px; max-height: 240px; padding: 7px; border: 1px solid var(--border); border-radius: 10px; background: #fffaf4; box-shadow: 0 15px 30px rgba(77, 50, 20, 0.13); overflow: auto; }
.filter-option { display: flex; align-items: center; gap: 8px; padding: 8px 7px; border-radius: 6px; color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 600; }
.filter-option:hover { background: var(--accent-soft); }
.filter-option input, .table-check, .market-check input { accent-color: var(--accent); }
.date-range { display: flex; align-items: center; gap: 6px; min-height: 39px; margin-top: 7px; }
.date-range input { width: 100%; min-width: 0; height: 39px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); background: var(--input); font-size: 11px; outline: none; }
.date-range input:focus, .modal input:focus, .modal select:focus { border-color: rgba(197, 92, 31, 0.5); box-shadow: 0 0 0 3px var(--accent-soft); }
.date-range span { color: var(--dim); }
.legend-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--card-2); }
.legend-label { color: var(--dim); font-size: 9px; font-weight: 800; letter-spacing: 0.1em; }
.legend-items { flex-wrap: wrap; gap: 9px; }
.legend-item, .status-key { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 600; }
.legend-swatch { width: 7px; height: 7px; border-radius: 2px; background: var(--market-color); }
.campaign-key { width: 15px; height: 7px; border-radius: 2px; background: linear-gradient(90deg, #c55c1f 0 33%, #8e5b87 33% 66%, #4f8465 66%); }
.legend-divider { width: 1px; height: 18px; margin: 0 3px; background: var(--border); }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.status-dot.active { background: var(--green); }
.status-dot.planned { background: var(--amber); }
.status-dot.finished { background: var(--dim); }
.status-dot.cancelled { background: var(--red); }

.result-count { padding: 6px 9px; border: 1px solid rgba(197, 92, 31, 0.18); border-radius: 999px; color: var(--accent-secondary); background: var(--accent-soft); font-size: 10px; font-weight: 800; }
.view-switch { display: inline-flex; align-items: center; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--card-2); }
.view-switch-button { min-height: 27px; padding: 0 9px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 10px; font-weight: 800; }
.view-switch-button:hover { color: var(--accent); }
.view-switch-button.active { color: var(--accent-secondary); background: var(--input); box-shadow: 0 1px 3px rgba(77, 50, 20, 0.1); }
.timeline-scroller { --timeline-width: 760px; overflow-x: auto; }
.timeline-header-grid, .timeline-row { display: grid; grid-template-columns: 280px minmax(var(--timeline-width), 1fr); min-width: calc(280px + var(--timeline-width)); }
.timeline-header-grid { min-height: 48px; border-bottom: 1px solid var(--border); background: var(--card-2); }
.row-title { display: flex; align-items: center; padding: 0 18px; border-right: 1px solid var(--border); color: var(--dim); font-size: 9px; font-weight: 800; letter-spacing: 0.1em; }
.axis { position: relative; min-height: 72px; overflow: hidden; }
.axis-month-row, .axis-unit-row { position: absolute; left: 0; right: 0; display: block; }
.axis-month-row { top: 0; height: 29px; border-bottom: 1px solid var(--border); }
.axis-unit-row { top: 29px; bottom: 0; }
.axis-segment { position: absolute; top: 0; bottom: 0; overflow: hidden; border-right: 1px solid rgba(84, 61, 28, 0.11); }
.axis-month-segment { padding: 7px 9px; color: var(--accent-secondary); background: rgba(244, 236, 225, 0.54); font-size: 10px; font-weight: 700; white-space: nowrap; }
.axis-unit-segment { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 3px; color: var(--dim); background: rgba(255, 252, 248, 0.3); font-family: "JetBrains Mono", monospace; font-size: 9px; white-space: nowrap; }
.axis-unit-segment:first-child { justify-content: flex-start; padding-left: 9px; }
.axis-unit-label { overflow: hidden; text-overflow: ellipsis; }
.axis-unit-week { display: block; margin-bottom: 2px; color: var(--accent); font-family: "DM Sans", sans-serif; font-size: 8px; font-weight: 800; }
.timeline-row { min-height: 76px; border-bottom: 1px solid rgba(84, 61, 28, 0.11); }
.timeline-row:last-child { border-bottom: 0; }
.row-label { display: flex; flex-direction: column; justify-content: center; gap: 5px; padding: 10px 18px; border-right: 1px solid var(--border); background: rgba(244, 236, 225, 0.42); }
.row-sku { overflow: hidden; color: var(--text); font-family: "JetBrains Mono", monospace; font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.market-pill { align-self: flex-start; padding: 3px 7px; border: 1px solid color-mix(in srgb, var(--market-color) 35%, transparent); border-radius: 999px; color: var(--market-color); background: color-mix(in srgb, var(--market-color) 9%, transparent); font-size: 9px; font-weight: 800; }
.row-context { display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--dim); font-size: 9px; line-height: 1.25; }
.row-context strong { color: var(--muted); font-weight: 800; }
.track { position: relative; min-height: 76px; background: repeating-linear-gradient(to right, transparent 0, transparent calc(var(--unit-size) - 1px), rgba(84, 61, 28, 0.07) calc(var(--unit-size) - 1px), rgba(84, 61, 28, 0.07) var(--unit-size)); }
.today-line { position: absolute; z-index: 3; top: 0; bottom: 0; width: 1px; background: #c43f32; box-shadow: 0 0 0 1px rgba(196, 63, 50, 0.06); }
.deal-bar { position: absolute; z-index: 2; top: 15px; bottom: 15px; min-width: 22px; padding: 7px 10px; overflow: hidden; border: 1px solid color-mix(in srgb, var(--market-color) 70%, #fff); border-radius: 7px; color: #fffaf5; background: var(--market-color); box-shadow: 0 4px 10px color-mix(in srgb, var(--market-color) 20%, transparent); text-align: left; cursor: grab; touch-action: none; user-select: none; }
.deal-bar:hover { filter: brightness(0.95); transform: translateY(-1px); }
.deal-bar.is-dragging { z-index: 6; cursor: grabbing; filter: brightness(0.95); }
.deal-name, .deal-type { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.deal-resize-handle { position: absolute; z-index: 4; top: 0; bottom: 0; width: 9px; opacity: 0; background: rgba(255, 250, 245, 0.34); cursor: ew-resize; transition: opacity 0.14s ease; }
.deal-resize-handle.left { left: 0; border-radius: 6px 0 0 6px; }
.deal-resize-handle.right { right: 0; border-radius: 0 6px 6px 0; }
.deal-bar:hover .deal-resize-handle, .deal-bar.is-dragging .deal-resize-handle { opacity: 1; }
.deal-name { font-size: 10px; font-weight: 800; }
.deal-type { margin-top: 2px; opacity: 0.82; font-size: 8px; }
.deal-bar.status-finished { opacity: 0.54; filter: saturate(0.55); }
.deal-bar.status-cancelled { opacity: 0.38; text-decoration: line-through; }
.timeline-footer { padding: 11px 20px; border-top: 1px solid var(--border); color: var(--dim); background: var(--card-2); font-size: 10px; }
.today-marker-key { display: inline-block; width: 2px; height: 11px; margin-right: 5px; background: #c43f32; vertical-align: -2px; }
.footer-separator { margin: 0 6px; color: rgba(84, 61, 28, 0.3); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--dim); background: var(--card-2); font-size: 9px; font-weight: 800; letter-spacing: 0.09em; text-align: left; }
td { padding: 12px 14px; border-bottom: 1px solid rgba(84, 61, 28, 0.1); color: var(--muted); font-size: 11px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(197, 92, 31, 0.035); }
.check-column { width: 40px; text-align: center; }
.sku-cell { color: var(--text); font-family: "JetBrains Mono", monospace; font-weight: 600; }
.market-cell { color: var(--market-color); font-weight: 800; }
.deal-cell strong, .deal-cell span { display: block; }
.deal-cell strong { color: var(--text); font-size: 11px; }
.deal-cell span { margin-top: 3px; color: var(--dim); font-size: 9px; }
.period-cell { font-family: "JetBrains Mono", monospace; font-size: 10px; }
.status-badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; font-size: 9px; font-weight: 800; }
.status-badge.active { color: var(--green); background: rgba(22, 132, 91, 0.1); }
.status-badge.planned { color: var(--amber); background: rgba(183, 121, 31, 0.1); }
.status-badge.finished { color: var(--dim); background: rgba(84, 61, 28, 0.08); }
.status-badge.cancelled { color: var(--red); background: rgba(180, 35, 24, 0.08); }
.row-actions { display: flex; align-items: center; gap: 6px; }
.row-edit, .row-delete { min-width: 28px; height: 28px; padding: 0 8px; border: 1px solid var(--border); border-radius: 7px; color: var(--muted); background: var(--input); font-size: 10px; font-weight: 800; }
.row-edit:hover { color: var(--accent); border-color: rgba(197, 92, 31, 0.3); }
.row-delete { color: var(--red); border-color: rgba(180, 35, 24, 0.18); background: rgba(180, 35, 24, 0.05); }
.row-delete:hover { color: #8f1c14; border-color: rgba(180, 35, 24, 0.34); background: rgba(180, 35, 24, 0.1); }
.empty-state { padding: 40px 20px; color: var(--muted); text-align: center; }
.empty-state .empty-icon { margin-bottom: 8px; color: var(--accent); font-size: 25px; }
.empty-state strong { color: var(--text); }
.empty-state p { margin-top: 5px; color: var(--dim); font-size: 11px; }

.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(38, 27, 18, 0.45); backdrop-filter: blur(3px); }
.modal { position: relative; width: min(590px, 100%); max-height: calc(100vh - 40px); padding: 28px; overflow-y: auto; border: 1px solid var(--border); border-radius: 16px; background: #fbf4eb; box-shadow: 0 24px 60px rgba(38, 27, 18, 0.24); }
.modal-close { position: absolute; top: 15px; right: 15px; width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); background: var(--input); font-size: 18px; }
.modal h2 { margin-top: 5px; font-size: 23px; }
.modal-description { margin: 7px 0 22px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.modal form > label, .form-row { margin-top: 14px; }
.form-row.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal input[type="text"], .modal input[type="date"], .modal select { display: block; width: 100%; height: 40px; margin-top: 7px; padding: 0 11px; border: 1px solid var(--border); border-radius: 8px; outline: none; color: var(--text); background: var(--input); font-size: 12px; }
.color-picker { display: flex; align-items: center; gap: 10px; margin-top: 7px; }
.color-picker input[type="color"] { width: 44px; height: 40px; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--input); cursor: pointer; }
.color-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.color-preset { width: 22px; height: 22px; padding: 0; border: 2px solid transparent; border-radius: 50%; background: var(--preset-color); box-shadow: 0 0 0 1px rgba(84, 61, 28, 0.15); }
.color-preset:hover, .color-preset.selected { border-color: #fffaf5; box-shadow: 0 0 0 2px var(--preset-color), 0 0 0 3px rgba(84, 61, 28, 0.16); }
.form-hint { display: block; margin-top: 6px; color: var(--dim); font-size: 9px; font-weight: 500; letter-spacing: 0; }
.modal fieldset { margin: 16px 0 0; padding: 12px; border: 1px solid var(--border); border-radius: 9px; }
.modal legend { padding: 0 5px; color: var(--dim); font-size: 10px; font-weight: 800; letter-spacing: 0.08em; }
.market-check-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.market-check { display: flex; align-items: center; gap: 5px; padding: 7px 5px; border-radius: 5px; color: var(--muted); font-size: 10px; font-weight: 700; cursor: pointer; }
.market-check:hover { background: var(--accent-soft); }
.form-error { min-height: 18px; margin-top: 8px; color: var(--red); font-size: 10px; font-weight: 700; }
.automatic-status-note { display: flex; align-items: center; gap: 6px; margin-top: 14px; color: var(--muted); font-size: 10px; }
.automatic-status-note span { color: var(--green); font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.confirm-modal { width: min(460px, 100%); }
.danger-confirm-button { padding: 10px 15px; border: 1px solid var(--red); border-radius: 8px; color: #fffaf5; background: var(--red); box-shadow: 0 5px 14px rgba(180, 35, 24, 0.16); font-size: 12px; font-weight: 700; }
.danger-confirm-button:hover { border-color: #8f1c14; background: #8f1c14; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1040px) {
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .date-field { grid-column: span 2; }
}

@media (max-width: 760px) {
  .main-content { padding: 14px 14px 32px; }
  .topbar { flex-wrap: wrap; }
  .topbar-context { display: none; }
  .topbar-actions { margin-left: auto; }
  .topbar-actions .ghost-button { display: none; }
  .page-heading { align-items: flex-start; flex-direction: column; padding: 26px 0 18px; }
  .heading-note { align-self: stretch; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric-card { min-height: 76px; padding: 11px; gap: 8px; }
  .metric-icon { width: 29px; height: 29px; font-size: 14px; }
  .metric-label { font-size: 8px; }
  .metric-card strong { font-size: 19px; }
  .metric-trend { display: none; }
  .panel-header { padding: 16px; }
  .filter-grid { grid-template-columns: 1fr; padding: 14px 16px 10px; }
  .date-field { grid-column: auto; }
  .legend-row { padding: 11px 16px; }
  .legend-divider { display: none; }
  .timeline-header-grid, .timeline-row { grid-template-columns: 220px minmax(var(--timeline-width), 1fr); min-width: calc(220px + var(--timeline-width)); }
  .row-title, .row-label { padding-left: 14px; padding-right: 14px; }
  .timeline-footer { padding: 11px 16px; }
  .timeline-header { align-items: flex-start; }
  .timeline-actions { flex-wrap: wrap; justify-content: flex-end; }
  .table-actions #selectedCount { display: none; }
  .deals-panel .panel-header { align-items: flex-start; }
  .modal { padding: 23px 18px; }
  .market-check-grid { grid-template-columns: repeat(3, 1fr); }
}
