:root {
  --gold: #c9a227;
  --gold-light: #e6c65c;
  --bg: #0f1210;
  --panel: #171b18;
  --panel-2: #1d221e;
  --text: #f2ede1;
  --muted: #9a9488;
  --border: rgba(201, 162, 39, 0.35);
  --border-soft: rgba(201, 162, 39, 0.18);
  --green: #6fae6f;
  --red: #d97a6f;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: Georgia, 'Times New Roman', serif; }
body {
  min-height: 100%;
  background:
    radial-gradient(circle at 50% -10%, rgba(201,162,39,0.10), transparent 60%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.02) 0 2px, transparent 2px 40px),
    var(--bg);
}
a { color: var(--gold-light); }
h1, h2, h3 { color: var(--gold-light); letter-spacing: 0.02em; margin-top: 0; }
.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 0.78rem; }

/* ---- nav ---- */
.site-header {
  border-bottom: 1px solid var(--border-soft);
  background: rgba(15, 18, 16, 0.9);
  position: sticky; top: 0; z-index: 50;
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; flex-wrap: wrap; gap: 10px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand .crown { color: var(--gold-light); font-size: 1.5rem; }
.brand-name { color: var(--gold-light); font-weight: 700; font-size: 1.15rem; letter-spacing: 0.02em; }
.nav-links { display: flex; gap: 22px; flex-wrap: wrap; }
.nav-links a { color: var(--text); text-decoration: none; font-size: 0.95rem; letter-spacing: 0.02em; }
.nav-links a:hover, .nav-links a.active { color: var(--gold-light); }
.nav-phone { color: var(--gold-light); font-weight: 700; text-decoration: none; white-space: nowrap; }

/* ---- hero ---- */
.hero { padding: 64px 0 40px; text-align: center; }
.hero .crown-big { font-size: 2.4rem; color: var(--gold-light); }
.hero h1 { font-size: 2.3rem; margin: 8px 0 6px; }
.hero .sub { color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.9rem; margin-bottom: 22px; }
.hero p.lead { max-width: 640px; margin: 0 auto 28px; font-size: 1.1rem; line-height: 1.6; }
.hero-ctas { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* ---- cards / sections ---- */
.card { background: var(--panel); border: 1px solid var(--border-soft); border-radius: 6px; padding: 28px; margin-bottom: 24px; }
.section { padding: 30px 0; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 560px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }

.type-card { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px; padding: 20px; text-align: center; }
.type-card .mat-icon svg { width: 40px; height: 40px; color: var(--gold-light); }
.type-card h3 { margin: 10px 0 4px; font-size: 1.15rem; }
.type-card p { color: var(--muted); font-size: 0.88rem; line-height: 1.5; }

/* ---- buttons ---- */
.btn {
  display: inline-block; padding: 12px 22px; border-radius: 4px; border: 1px solid var(--gold);
  background: linear-gradient(180deg, var(--gold-light), var(--gold)); color: #1a1608; font-weight: 700;
  text-decoration: none; cursor: pointer; font-family: inherit; font-size: 0.95rem;
}
.btn:hover { filter: brightness(1.06); }
.btn-outline { background: transparent; color: var(--gold-light); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); padding: 8px 12px; font-weight: 400; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }

/* ---- forms ---- */
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; color: var(--text); font-size: 0.92rem; }
.field .hint { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }
input[type="text"], input[type="number"], input[type="email"], select {
  width: 100%; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--border-soft);
  color: var(--text); border-radius: 4px; font-family: inherit; font-size: 0.95rem;
}
input:focus, select:focus { outline: none; border-color: var(--gold); }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.checkbox-row input { width: auto; }
.radio-group { display: flex; gap: 18px; flex-wrap: wrap; }
.radio-group label { display: flex; align-items: center; gap: 6px; font-size: 0.92rem; }
.radio-group input { width: auto; }
fieldset { border: 1px solid var(--border-soft); border-radius: 6px; padding: 16px; margin: 0 0 20px; }
legend { padding: 0 8px; color: var(--gold-light); font-weight: 700; font-size: 0.95rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

.gate-row { display: grid; grid-template-columns: 1fr 90px 40px; gap: 8px; margin-bottom: 8px; align-items: center; }
.perimeter-box { background: var(--panel-2); border: 1px dashed var(--border); border-radius: 6px; padding: 16px; margin-bottom: 18px; }
.perimeter-box .two-col { align-items: end; margin-bottom: 10px; }

/* ---- results / tables ---- */
.hidden { display: none !important; }
.result-head { margin-bottom: 8px; }
.tab-buttons { display: flex; gap: 6px; margin: 20px 0 0; flex-wrap: wrap; }
.tab-btn { padding: 10px 16px; background: var(--panel-2); border: 1px solid var(--border-soft); border-bottom: none;
  color: var(--muted); cursor: pointer; border-radius: 4px 4px 0 0; font-family: inherit; }
.tab-btn.active { color: var(--gold-light); background: var(--panel); border-color: var(--border); }
.tab-panel { display: none; border: 1px solid var(--border-soft); border-top: none; padding: 18px; background: var(--panel); border-radius: 0 0 6px 6px; overflow-x: auto; }
.tab-panel.active { display: block; }

table { width: 100%; border-collapse: collapse; }
table.data-table, #detail-table, #compare-table, #summary-table { min-width: 600px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border-soft); text-align: left; font-size: 0.9rem; vertical-align: top; }
th { color: var(--gold-light); font-weight: 700; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.cat-row td { background: rgba(201,162,39,0.08); color: var(--gold-light); font-weight: 700; text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.06em; }
tr.strong td { font-weight: 700; border-top: 1px solid var(--border); }
tr.grand td { font-weight: 700; font-size: 1.15rem; color: var(--gold-light); border-top: 2px solid var(--gold); padding-top: 14px; }
td.cheapest { color: var(--green); font-weight: 700; }
td.chosen { text-decoration: underline; }
.best-tag { font-size: 0.65rem; background: var(--green); color: #06170a; padding: 1px 5px; border-radius: 3px; vertical-align: middle; }
.mat-cell { display: flex; gap: 10px; align-items: flex-start; min-width: 220px; }
.mat-icon svg { width: 26px; height: 26px; color: var(--gold-light); flex-shrink: 0; }
.mat-name { font-weight: 700; }
.mat-spec { color: var(--muted); font-size: 0.78rem; }
.row-supplier { min-width: 170px; }

/* ---- sticky total bar ---- */
#sticky-bar {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--panel); border-top: 1px solid var(--gold);
  padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; z-index: 60;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
}
#sticky-bar .label { color: var(--muted); font-size: 0.85rem; }
#sticky-bar .amount { color: var(--gold-light); font-size: 1.3rem; font-weight: 700; }

/* ---- footer ---- */
.site-footer { border-top: 1px solid var(--border-soft); padding: 30px 0; margin-top: 50px; text-align: center; color: var(--muted); font-size: 0.85rem; }
.site-footer a { color: var(--muted); }

/* ---- filters bar (materials.html) ---- */
.filters-bar { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 12px; margin-bottom: 18px; }
@media (max-width: 700px) { .filters-bar { grid-template-columns: 1fr; } }

/* ---- editable prices (admin/materials.php) ---- */
#cat-results { overflow-x: auto; }
.increase-bar { display: grid; grid-template-columns: 140px 1fr 1fr auto; gap: 12px; align-items: end; }
@media (max-width: 800px) { .increase-bar { grid-template-columns: 1fr; } }
.price-table td.price-cell { min-width: 130px; }
.price-table .dollar { color: var(--muted); margin-right: 3px; }
.price-table input.price-in { width: 84px; display: inline-block; padding: 6px 8px; text-align: right; color: inherit; font-weight: inherit; }
.price-table td.edited input.price-in { border-color: var(--gold); background: rgba(201,162,39,0.14); }
.price-table input.price-in.invalid { border-color: var(--red); }
.price-table .best-tag { margin-left: 5px; }
.price-table .row-reset { padding: 4px 10px; font-size: 0.78rem; }
.price-status { border: 1px solid var(--green); color: var(--green); border-radius: 6px; padding: 10px 14px; margin-bottom: 18px; }
.price-status.err { border-color: var(--red); color: var(--red); }
.price-status[hidden], .price-save-bar[hidden] { display: none; }
.price-save-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60; background: var(--panel); border-top: 1px solid var(--gold);
  padding: 12px 20px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.4); color: var(--gold-light); font-weight: 700;
}
.price-history { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
.price-history li { padding: 8px 0; border-bottom: 1px solid var(--border-soft); font-size: 0.9rem; }

/* ---- sketch pad ---- */
/* minmax(0,1fr): a bare 1fr track won't shrink below the SVG's intrinsic width, which pushed the page wider than a phone screen. */
.sketch-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
@media (max-width: 900px) { .sketch-layout { grid-template-columns: minmax(0, 1fr); } }
#sketch-svg { display: block; max-width: 100%; }
.sketch-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.sketch-toolbar .sep { width: 1px; align-self: stretch; background: var(--border-soft); margin: 0 4px; }
.tool-btn {
  padding: 8px 14px; border-radius: 4px; border: 1px solid var(--border-soft); background: var(--panel-2);
  color: var(--text); cursor: pointer; font-family: inherit; font-size: 0.85rem; white-space: nowrap;
}
.tool-btn.active { background: var(--gold); color: #1a1608; border-color: var(--gold); font-weight: 700; }
.tool-btn:disabled { opacity: 0.4; cursor: default; }
.sketch-canvas-wrap {
  position: relative; border: 1px solid var(--border-soft); border-radius: 6px; background: #0a0d0b;
  touch-action: none; overflow: hidden; width: 100%; aspect-ratio: 4 / 3;
}
.sketch-canvas-wrap svg { width: 100%; height: 100%; display: block; touch-action: none; }
.sketch-floating-panel {
  position: absolute; background: var(--panel); border: 1px solid var(--gold); border-radius: 6px;
  padding: 10px; z-index: 20; box-shadow: 0 8px 20px rgba(0,0,0,0.5); font-size: 0.85rem;
}
.sketch-floating-panel .field { margin-bottom: 8px; }
.sketch-floating-panel input[type="number"] { width: 70px; display: inline-block; }
.sketch-side-panel { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px; padding: 16px; }
.sketch-side-panel h3 { font-size: 1rem; margin-bottom: 10px; }
.sketch-legend { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; font-size: 0.78rem; }
.sketch-legend span { display: inline-flex; align-items: center; gap: 5px; }
.sketch-legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.zone-table { margin-top: 10px; }
.zone-table td, .zone-table th { padding: 6px 8px; font-size: 0.82rem; }
/* Tool rail: Draw / Select / Move etc. stacked down the left edge of the drawing. */
.sketch-stage { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: start; }
.sketch-stage-main { min-width: 0; }
.sketch-rail { display: flex; flex-direction: column; gap: 5px; width: 76px; }
.sketch-rail .tool-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 5px 3px; min-height: 42px; font-size: 0.68rem; line-height: 1.15; white-space: normal; text-align: center;
}
.sketch-rail .ti { font-size: 1.05rem; line-height: 1; }
.sketch-rail .sep { display: block; height: 1px; background: var(--border-soft); margin: 3px 0; }
/* Phones: the drawing needs the full width, so the tools go back to a row above it. */
@media (max-width: 600px) {
  .sketch-stage { grid-template-columns: minmax(0, 1fr); }
  .sketch-rail { flex-direction: row; flex-wrap: wrap; width: auto; }
  .sketch-rail .tool-btn { flex: 1 0 58px; }
  .sketch-rail .sep { display: none; }
}
/* Quick shapes: one row under the drawing (scrolls sideways on a narrow phone instead of wrapping). */
.sketch-presets { margin-top: 8px; }
.preset-row { display: flex; flex-wrap: nowrap; gap: 8px; align-items: center; overflow-x: auto; padding-bottom: 2px; }
.preset-row > * { flex: 0 0 auto; }
.preset-panel { margin-top: 8px; }
.preset-panel {
  flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--gold); border-radius: 6px; padding: 12px;
}
.preset-panel[hidden], .preset-sizes[hidden] { display: none; }
.preset-panel label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.preset-panel input[type="number"] { width: 90px; }
.preset-sizes { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.gate-row { border-top: 1px solid var(--border-soft); padding-top: 10px; margin-top: 10px; }
.gate-row .checkbox-row { margin-bottom: 6px; }
.gate-pos { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 2px; font-size: 0.85rem; }
.gate-pos input[type="number"] { width: 62px; padding: 7px 8px; }
.gate-pos .btn { padding: 7px 11px; }
.gate-sections strong { color: var(--gold-light); }
#sketch-hint { min-height: 20px; color: var(--gold-light); font-size: 0.85rem; margin-bottom: 8px; }

@media print {
  .site-header, .site-footer, #sticky-bar, .card.form-card, .btn-row, .tab-buttons, .no-print { display: none !important; }
  .tab-panel { display: block !important; border: none; padding: 0; margin-bottom: 24px; }
  body { background: #fff; color: #000; }
  table, th, td { border-color: #999 !important; }
  .mat-icon, td.cheapest, td.chosen, tr.grand td { color: #000 !important; }
}

/* Detected-runs table scrolls inside its card on phones instead of widening the page. */
#zones-wrap { overflow-x: auto; }
