/* ==========================================================================
   Snap Lock Box Dieline Generator — Stylesheet
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design Tokens
   -------------------------------------------------------------------------- */

:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe3ee;
  --blue: #2563eb;
}

/* --------------------------------------------------------------------------
   Base & Reset
   -------------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: 'Space Grotesk', sans-serif;
  background: #f4f7fb;
  color: var(--ink);
}

main {
  display: flex;
  flex-direction: column;
  max-width: 1500px;
  height: 100vh;
  margin: 0 auto;
  padding: 16px 20px;
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */

h1 {
  margin: 0 0 4px;
  font-size: clamp(22px, 2.5vw, 30px);
}

.sub {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */

.layout {
  display: grid;
  flex: 1;
  min-height: 0;
  grid-template-columns: 280px minmax(0, 1fr) 300px;
  gap: 14px;
}

/* Shared card surface for all three columns */
.panel,
.drawing,
.master-size {
  min-height: 0;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 5px 18px #0f172a0a;
}

/* --------------------------------------------------------------------------
   Left Panel — Box Measurements
   -------------------------------------------------------------------------- */

.panel {
  padding: 16px;
  overflow-y: auto;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

/* --------------------------------------------------------------------------
   Right Panel — Master Size
   -------------------------------------------------------------------------- */

.master-size {
  padding: 16px;
  overflow-y: auto;
}

.master-size h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.master-size .stats {
  grid-template-columns: 1fr;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

label {
  display: block;
  margin: 12px 0 6px;
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
}

.hint {
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}

/* Stacked secondary row */
.btns + .btns {
  margin-top: 8px;
}

button {
  padding: 11px 12px;
  font-family: inherit;
  font-weight: 700;
  color: white;
  cursor: pointer;
  background: var(--blue);
  border: 0;
  border-radius: 9px;
}

button.secondary {
  color: #1e293b;
  background: #e8eef8;
}

/* Reset button spans both columns */
#resetBtn {
  grid-column: 1 / -1;
}

/* --------------------------------------------------------------------------
   Center Column — Flat Layout Preview
   -------------------------------------------------------------------------- */

.drawing {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Toolbar & Legend
   -------------------------------------------------------------------------- */

.toolbar {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: #475569;
}

.key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 24px;
  border-top: 2px solid #dc2626;
}

.swatch.crease {
  border-color: #2563eb;
  border-top-style: dashed;
}

/* --------------------------------------------------------------------------
   Canvas & Zoom Controls
   -------------------------------------------------------------------------- */

.canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

.canvas svg {
  max-width: 100%;
  max-height: 100%;
}

.canvas .zoom-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  gap: 6px;
}

.canvas .zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 18px;
  font-weight: normal;
  color: var(--ink);
  cursor: pointer;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  transition: background 0.15s;
}

.canvas .zoom-btn:hover {
  background: #f1f5f9;
}

.canvas .zoom-btn.reset {
  font-size: 11px;
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   Inline SVG
   -------------------------------------------------------------------------- */

svg {
  display: block;
  min-width: 0;
  width: 100%;
  height: auto;
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Stats Cards
   -------------------------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.stat {
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

.stat small {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
}

.stat strong {
  font-size: 16px;
}

/* --------------------------------------------------------------------------
   Alerts
   -------------------------------------------------------------------------- */

.warning {
  margin-top: 14px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #9a3412;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 10px;
}

.error {
  display: none;
  margin-top: 12px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #991b1b;
  white-space: pre-wrap;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
}

/* --------------------------------------------------------------------------
   Responsive — Tablet / Narrow Desktop
   -------------------------------------------------------------------------- */

@media (max-width: 1100px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  main {
    display: block;
    height: auto;
    padding: 14px;
  }

  .layout {
    display: block;
  }

  .panel,
  .drawing,
  .master-size {
    margin-bottom: 14px;
  }

  .panel,
  .master-size {
    overflow-y: visible;
  }

  .drawing {
    display: block;
    overflow: visible;
  }

  .canvas {
    height: 65vh;
  }

  .master-size .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* --------------------------------------------------------------------------
   Responsive — Mobile
   -------------------------------------------------------------------------- */

@media (max-width: 700px) {
  .master-size .stats {
    grid-template-columns: 1fr 1fr;
  }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */

@media print {
  body {
    height: auto;
    overflow: visible;
    background: white;
  }

  main {
    display: block;
    max-width: none;
    height: auto;
    padding: 0;
  }

  h1,
  .sub,
  .panel,
  .toolbar,
  .stats,
  .warning,
  .error,
  .zoom-controls,
  .master-size h2 {
    display: none !important;
  }

  .layout {
    display: block;
  }

  .drawing {
    display: block;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .canvas {
    height: auto;
    overflow: visible;
    border: 0;
  }

  svg {
    min-width: 0;
    width: 100%;
  }
}