/* ============================================================
   S45 Jeans Co — Order Form
   Design tokens: denim indigo + copper stitch, paper docket
   ============================================================ */

:root {
  --indigo-950: #14213D;
  --indigo-800: #1F3A5F;
  --indigo-700: #274a76;
  --indigo-600: #2D5A8F;
  --indigo-100: #E8EEF5;

  --copper-700: #8a5326;
  --copper-600: #A8632C;
  --copper-500: #C17A3F;
  --copper-300: #E0A876;
  --copper-100: #F5E3D1;

  --paper: #F7F3EC;
  --paper-2: #FFFDF9;
  --ink: #1C1A17;
  --ink-soft: #5B564C;
  --ink-faint: #948E80;
  --rivet: #8A7A5C;

  --danger: #A6402A;
  --success: #3F6B4E;

  --font-display: 'Oswald', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;

  --shadow-card: 0 10px 30px rgba(20, 33, 61, 0.14), 0 2px 8px rgba(20, 33, 61, 0.08);
  --shadow-pop: 0 12px 28px rgba(20, 33, 61, 0.28);

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--indigo-950);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--indigo-800), var(--indigo-950) 60%);
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

::selection { background: var(--copper-300); color: var(--indigo-950); }

button { font-family: inherit; }

a { color: var(--copper-300); }

/* ---------------- App Bar ---------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: linear-gradient(180deg, rgba(20,33,61,0.98), rgba(20,33,61,0.9));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(224,168,118,0.18);
}

.appbar__brand { display: flex; align-items: center; gap: 12px; }

.appbar__logo {
  width: 96px;
  height: auto;
  aspect-ratio: 646 / 372;
  border-radius: 8px;
  background: var(--paper-2);
  box-shadow: 0 2px 6px rgba(0,0,0,0.35), 0 0 0 1px rgba(224,168,118,0.35);
  padding: 4px 6px;
  object-fit: contain;
}

.appbar__title { display: flex; flex-direction: column; line-height: 1.15; }

.appbar__company {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--paper-2);
  font-size: 1.05rem;
}

.appbar__firm {
  font-size: 0.72rem;
  color: var(--copper-300);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.iconbtn {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(224,168,118,0.3);
  background: rgba(255,255,255,0.04);
  color: var(--paper-2);
  cursor: pointer;
}
.iconbtn:active { background: rgba(255,255,255,0.12); }

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--copper-500);
  color: var(--indigo-950);
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ---------------- Layout ---------------- */
.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 14px 90px;
}

/* ---------------- Docket Card ---------------- */
.docket {
  position: relative;
  background: var(--paper-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  border: 1px solid rgba(20,33,61,0.06);
}

.docket__stitchtop,
.docket__stitchbottom {
  height: 0;
  border-top: 3px dashed var(--copper-300);
  margin: 0 18px;
  opacity: 0.9;
}
.docket__stitchtop { margin-top: 14px; }
.docket__stitchbottom { margin-bottom: 14px; }

.docket__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 20px 10px;
  flex-wrap: wrap;
}

.tag-chip {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--indigo-800);
  background: var(--indigo-100);
  padding: 6px 12px;
  border-radius: 999px;
}

.ordno { text-align: right; }
.ordno__label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.ordno__value {
  display: block;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--copper-700);
  font-size: 1rem;
  letter-spacing: 0.02em;
}

/* ---------------- Sections / Fields ---------------- */
.section {
  border: none;
  margin: 6px 14px 0;
  padding: 14px 6px 6px;
  border-top: 1px solid rgba(20,33,61,0.07);
}
.section:first-of-type { border-top: none; }

.section__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--indigo-800);
  padding: 0 8px;
  margin-bottom: 6px;
}

.rivet-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--copper-500);
  box-shadow: 0 0 0 3px var(--copper-100);
  flex: none;
}

.field {
  padding: 8px;
}

.field-row {
  display: flex;
  gap: 4px;
}
.field-row .field { flex: 1; min-width: 0; }

label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
  letter-spacing: 0.01em;
}
label em {
  font-style: normal;
  color: var(--danger);
  margin-left: 2px;
}

input, textarea {
  width: 100%;
  border: 1.5px solid #E4DFD3;
  background: var(--paper);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 0.95rem;
  font-family: var(--font-body);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--copper-500);
  box-shadow: 0 0 0 3px var(--copper-100);
  background: var(--paper-2);
}
textarea { resize: vertical; min-height: 44px; font-family: var(--font-body); }

input::placeholder, textarea::placeholder { color: var(--ink-faint); }

/* ---------------- Items Table ---------------- */
.items { padding: 4px 8px; }

.items__head {
  display: grid;
  grid-template-columns: 40px 1.1fr 1.6fr 1.1fr 0.9fr 34px;
  gap: 6px;
  padding: 0 6px 6px;
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.item-row {
  display: grid;
  grid-template-columns: 40px 1.1fr 1.6fr 1.1fr 0.9fr 34px;
  gap: 6px;
  align-items: center;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
}
.item-row:nth-child(odd) { background: rgba(193,122,63,0.05); }

.item-row .sr {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--indigo-700);
  text-align: center;
  font-size: 0.9rem;
}

.item-row input {
  padding: 8px 9px;
  font-size: 0.88rem;
}

.item-row .price-input { font-family: var(--font-mono); text-align: right; }

.rowdel {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.rowdel:hover, .rowdel:active { color: var(--danger); background: rgba(166,64,42,0.1); }

.totals {
  display: flex;
  justify-content: flex-start;
  padding: 12px 10px 4px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  border-top: 1px dashed #E4DFD3;
  margin-top: 8px;
}
.totals strong { color: var(--indigo-800); font-family: var(--font-mono); }

/* ---------------- Buttons ---------------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }

.btn--full { width: calc(100% - 12px); margin: 8px 6px 2px; }

.btn--ghost {
  background: transparent;
  border: 1.5px dashed var(--copper-300);
  color: var(--copper-700);
}
.btn--ghost:active { background: var(--copper-100); }

.btn--primary {
  background: var(--indigo-800);
  color: var(--paper-2);
  box-shadow: 0 4px 10px rgba(31,58,95,0.35);
}
.btn--primary:active { background: var(--indigo-700); }

.btn--copper {
  background: var(--copper-500);
  color: #fff;
  box-shadow: 0 4px 10px rgba(193,122,63,0.35);
}
.btn--copper:active { background: var(--copper-600); }

.btn--outline {
  background: var(--paper-2);
  border: 1.5px solid #DCD5C4;
  color: var(--ink-soft);
}

/* ---------------- Action bar ---------------- */
.actionbar {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
  margin-top: 16px;
}
.actionbar .btn:nth-child(1) { grid-column: 1; }
.actionbar .btn:nth-child(2) { grid-column: 2; }
.actionbar .btn:nth-child(3),
.actionbar .btn:nth-child(4) { grid-column: span 1; }

@media (min-width: 480px) {
  .actionbar { grid-template-columns: repeat(4, 1fr); }
}

.footfine {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  justify-content: center;
  margin-top: 22px;
  font-size: 0.72rem;
  color: rgba(247,243,236,0.55);
  text-align: center;
}

/* ---------------- Drawer ---------------- */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(20,33,61,0.55);
  z-index: 30;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100dvh;
  width: min(88vw, 380px);
  background: var(--paper);
  z-index: 31;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 30px rgba(0,0,0,0.25);
  padding-top: env(safe-area-inset-top);
}
.drawer.open { transform: translateX(0); }

.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  border-bottom: 1px solid #E4DFD3;
}
.drawer__head h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--indigo-800);
  margin: 0;
}
.drawer .iconbtn { border-color: #DCD5C4; color: var(--indigo-800); background: var(--paper-2); }

.drawer__search { padding: 12px 16px; }
.drawer__search input { background: var(--paper-2); }

.drawer__list {
  overflow-y: auto;
  padding: 6px 12px 24px;
  flex: 1;
}

.order-card {
  background: var(--paper-2);
  border: 1px solid #E4DFD3;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.order-card:active { background: var(--indigo-100); }

.order-card__top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.order-card__no {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--copper-700);
}
.order-card__date { font-size: 0.72rem; color: var(--ink-faint); }
.order-card__party { font-weight: 600; margin-top: 4px; color: var(--ink); }
.order-card__meta { font-size: 0.78rem; color: var(--ink-soft); margin-top: 2px; }

.order-card__actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.order-card__actions button {
  flex: 1;
  border: none;
  background: var(--indigo-100);
  color: var(--indigo-800);
  border-radius: var(--radius-sm);
  padding: 7px 8px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}
.order-card__actions button.del { background: #F5DED8; color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--ink-faint);
  padding: 40px 20px;
  font-size: 0.88rem;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--indigo-950);
  color: var(--paper-2);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------------- Mobile: items become stacked cards ---------------- */
@media (max-width: 640px) {
  .items__head { display: none; }

  .item-row {
    grid-template-columns: 1fr;
    background: var(--paper) !important;
    border: 1px solid #E9E3D5;
    padding: 10px;
    margin-bottom: 8px;
    position: relative;
  }
  .item-row .sr {
    position: absolute;
    top: 8px;
    right: 40px;
    background: var(--indigo-100);
    color: var(--indigo-800);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 0.75rem;
  }
  .item-row .rowdel { position: absolute; top: 2px; right: 2px; }
  .item-row .field-wrap { margin-bottom: 6px; }
  .item-row .field-wrap:last-child { margin-bottom: 0; }
  .item-row .field-wrap label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
    margin-bottom: 3px;
  }
}

@media (min-width: 641px) {
  .item-row .field-wrap label { display: none; }
}

/* ---------------- Print / PDF template ---------------- */
.print-root {
  position: fixed;
  top: -99999px;
  left: -99999px;
  width: 794px; /* A4 @ 96dpi */
  background: #fff;
}

.pdfpage {
  width: 794px;
  min-height: 1123px;
  background: #fff;
  padding: 40px 44px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  line-height: 1.35;
  color: #1C1A17;
  position: relative;
  box-sizing: border-box;
}

.pdf-border {
  position: absolute;
  inset: 18px;
  border: 2px dashed #C17A3F;
  border-radius: 16px;
  pointer-events: none;
}

.pdf-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 3px solid #14213D;
  margin-bottom: 18px;
}
.pdf-brand { display: flex; gap: 14px; align-items: center; }
.pdf-brand img { width: 120px; height: auto; aspect-ratio: 646 / 372; object-fit: contain; border-radius: 6px; display: block; }
.pdf-brand h1 { font-family: 'Oswald', sans-serif; font-size: 22px; line-height: 1.2; margin: 0; color: #14213D; letter-spacing: 0.01em; }
.pdf-brand p { line-height: 1.2; margin: 4px 0 0; font-size: 11px; color: #A8632C; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.pdf-firm { text-align: right; font-size: 10.5px; line-height: 1.6; color: #5B564C; max-width: 240px; }
.pdf-firm strong { display: block; line-height: 1.3; color: #1C1A17; font-size: 12px; margin-bottom: 3px; }

.pdf-metabar {
  display: flex;
  justify-content: space-between;
  background: #F7F3EC;
  border: 1px dashed #E0A876;
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 18px;
  font-size: 11.5px;
}
.pdf-metabar div { line-height: 1.3; }
.pdf-metabar div span { display: block; line-height: 1.3; color: #948E80; text-transform: uppercase; font-size: 9.5px; letter-spacing: 0.08em; margin-bottom: 3px; }
.pdf-metabar div strong { display: block; line-height: 1.3; font-family: 'JetBrains Mono', monospace; color: #14213D; font-size: 13px; }

.pdf-section-title {
  font-family: 'Oswald', sans-serif;
  font-size: 12px;
  line-height: 1.3;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #1F3A5F;
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #E4DFD3;
}

.pdf-party {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
  font-size: 12px;
  line-height: 1.35;
  margin-bottom: 20px;
}
.pdf-party .full { grid-column: 1 / -1; }
.pdf-party label { display: block; line-height: 1.3; font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.06em; color: #948E80; margin-bottom: 3px; }
.pdf-party div.val { line-height: 1.35; color: #1C1A17; font-weight: 500; }

table.pdf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  line-height: 1.3;
  margin-bottom: 16px;
}
table.pdf-table th {
  background: #14213D;
  color: #F7F3EC;
  font-family: 'Oswald', sans-serif;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 10px;
  padding: 9px 8px 7px;
  text-align: left;
}
table.pdf-table td {
  padding: 8px 8px;
  line-height: 1.3;
  border-bottom: 1px solid #EDE8DC;
  vertical-align: middle;
}
table.pdf-table tr:nth-child(even) td { background: #FAF7F1; }
table.pdf-table td.num { font-family: 'JetBrains Mono', monospace; text-align: right; }
table.pdf-table td.center { text-align: center; font-family: 'JetBrains Mono', monospace; }

.pdf-totalrow {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 26px;
  padding: 8px 4px;
  font-size: 12.5px;
  line-height: 1.3;
  border-top: 2px solid #14213D;
}
.pdf-totalrow strong { font-family: 'JetBrains Mono', monospace; color: #14213D; }

.pdf-notes {
  margin-top: 10px;
  font-size: 11px;
  line-height: 1.45;
  color: #5B564C;
  background: #F7F3EC;
  border-left: 3px solid #C17A3F;
  padding: 8px 12px;
  border-radius: 0 8px 8px 0;
}

.pdf-footer {
  position: absolute;
  bottom: 34px;
  left: 44px;
  right: 44px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 9.5px;
  line-height: 1.3;
  color: #948E80;
  border-top: 1px dashed #DCD5C4;
  padding-top: 10px;
}

.pdf-sign {
  display: flex;
  justify-content: space-between;
  margin-top: 46px;
  padding: 0 10px;
}
.pdf-sign div { text-align: center; font-size: 10.5px; line-height: 1.3; color: #5B564C; }
.pdf-sign div .line { width: 160px; border-top: 1px solid #948E80; margin-bottom: 6px; padding-top: 34px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------- Lock Screen ---------------- */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1100px 600px at 50% -10%, var(--indigo-800), var(--indigo-950) 60%);
}
.lock-screen[hidden] { display: none; }

.lock-card {
  width: 100%;
  max-width: 360px;
  background: var(--paper-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 30px 26px 26px;
  text-align: center;
  border: 1px dashed var(--copper-300);
}

.lock-logo {
  width: 140px;
  height: auto;
  aspect-ratio: 646 / 372;
  object-fit: contain;
  margin: 0 auto 14px;
  display: block;
}

.lock-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--indigo-800);
  margin: 0 0 4px;
  letter-spacing: 0.01em;
}

.lock-sub {
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin: 0 0 20px;
}

.lock-field {
  position: relative;
  margin-bottom: 12px;
}
.lock-field input {
  padding-right: 44px;
  text-align: left;
  letter-spacing: 0.02em;
}

.lock-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 50%;
}
.lock-toggle:active { background: var(--indigo-100); color: var(--indigo-800); }

.lock-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin: -4px 0 12px;
  text-align: left;
}

.lock-submit { width: 100%; padding: 13px; font-size: 0.95rem; }

