/* ============================================================
   POLAR ICE — styles.css  (rebuild)
   ============================================================ */

:root {
  --blue:       #00AEEF;
  --blue-dark:  #0082B3;
  --blue-light: #E5F7FD;
  --black:      #0A0E14;
  --surface:    #F0F4F8;
  --success:    #10B981;
  --warning:    #F59E0B;
  --danger:     #EF4444;
  --text:       #1A202C;
  --muted:      #6B7280;
  --border:     #E2E8F0;
  --white:      #FFFFFF;
  --radius:     10px;
  --shadow:     0 2px 8px rgba(0,0,0,.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* iPhone: prevent text size adjust on rotation */
  -webkit-text-size-adjust: 100%;
  /* iPhone: smooth momentum scrolling */
  -webkit-overflow-scrolling: touch;
  /* iPhone: safe area bottom (home indicator) */
  padding-bottom: env(safe-area-inset-bottom);
}

/* Remove blue tap flash on all interactive elements */
a, button, input, select, textarea, label {
  -webkit-tap-highlight-color: transparent;
}

/* Prevent double-tap zoom on buttons */
button { touch-action: manipulation; }

/* ── HEADER ─────────────────────────────────────────────────── */
#app-header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--black);
  border-bottom: 3px solid var(--blue);
  display: flex;
  align-items: center;
  /* iPhone notch/Dynamic Island safe area */
  padding: 0 20px;
  padding-top: env(safe-area-inset-top);
  padding-left: calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
  height: calc(54px + env(safe-area-inset-top));
  gap: 14px;
}

#header-logo { height: 36px; object-fit: contain; display: block; }
#header-logo-text {
  color: var(--blue);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .04em;
}

nav { display: flex; gap: 2px; flex: 1; }

.nav-tab {
  background: none;
  border: none;
  color: #9CA3AF;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 15px;
  border-radius: 7px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  /* iPhone: proper touch target height */
  min-height: 44px;
  display: flex;
  align-items: center;
}
.nav-tab:hover  { color: #fff; background: rgba(255,255,255,.07); }
.nav-tab.active { color: var(--blue); background: rgba(0,174,239,.13); }

.lang-toggle {
  display: flex;
  background: rgba(255,255,255,.1);
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}
.lang-toggle button {
  background: none;
  border: none;
  color: #9CA3AF;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 11px;
  border-radius: 16px;
  cursor: pointer;
  transition: all .15s;
}
.lang-toggle button.active { background: var(--blue); color: #fff; }

/* ── VIEWS ──────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 18px 16px;
}

/* ── CARDS ──────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 10px;
}
.card.tint {
  background: var(--blue-light);
  border: 1px solid #BAE3F9;
}

.card-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--blue-dark);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-title .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--blue);
  flex-shrink: 0;
}

/* ── FORM ───────────────────────────────────────────────────── */
.row  { display: grid; gap: 10px; margin-bottom: 10px; }
.r2   { grid-template-columns: 1fr 1fr; }
.r3   { grid-template-columns: 1fr 1fr 1fr; }
.r2l  { grid-template-columns: 2fr 1fr; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  /* iPhone: 16px PREVENTS auto-zoom on focus */
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  /* iPhone: remove default styling */
  -webkit-appearance: none;
  appearance: none;
}
select {
  /* Re-add arrow for select since we removed appearance */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236B7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0,174,239,.1);
}
input[readonly] { background: #F8FAFC; color: var(--muted); cursor: default; box-shadow: none; }
textarea { resize: vertical; min-height: 56px; }

/* ── TOGGLES ────────────────────────────────────────────────── */
.tgl {
  display: flex;
  background: #E8EDF2;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.tgl button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #7A8899;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  /* iPhone: min touch target */
  min-height: 44px;
}
.tgl button.active {
  background: var(--white);
  color: var(--blue);
  font-weight: 700;
  box-shadow: 0 1px 5px rgba(0,0,0,.13);
}

/* ── INTERNAL SECTION ───────────────────────────────────────── */
.internal-box {
  border: 1.5px dashed #D1A424;
  border-radius: 8px;
  padding: 14px;
  margin-top: 14px;
  background: #FFFBEB;
}
.int-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--warning);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  padding: 3px 9px;
  border-radius: 5px;
  margin-bottom: 12px;
}

.deliv-live {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.deliv-live span {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 12px;
  color: var(--muted);
}
.deliv-live span strong { color: var(--text); }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.check-row input[type=checkbox] {
  width: 15px; height: 15px;
  accent-color: var(--blue);
  cursor: pointer;
}

/* ── PRODUCT TAGS ───────────────────────────────────────────── */
.ptag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 2px 9px;
  border-radius: 4px;
  margin-bottom: 10px;
}
.ptag-blue  { background: #DBEAFE; color: #1D4ED8; }
.ptag-teal  { background: #CCFBF1; color: #0F766E; }
.ptag-amber { background: #FEF3C7; color: #92400E; }

.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── RESULTS PANEL ──────────────────────────────────────────── */
.results {
  background: var(--black);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 10px;
  color: #fff;
  border: 1px solid #1E2530;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat {
  background: rgba(0,174,239,.08);
  border: 1px solid rgba(0,174,239,.15);
  border-radius: 8px;
  padding: 11px 10px;
  text-align: center;
}
.stat-n { font-size: 20px; font-weight: 800; color: var(--blue); line-height: 1; }
.stat-l { font-size: 10px; color: #6B7280; margin-top: 3px; text-transform: uppercase; letter-spacing: .04em; }

.lines { margin-bottom: 12px; }
.line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
  font-size: 13px;
  color: #9CA3AF;
}
.line:last-child { border-bottom: none; }
.line-v { font-weight: 600; color: #E5E7EB; }
.line-hidden { opacity: 0.3; }

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: 8px;
  background: rgba(0,174,239,.1);
  border: 1px solid rgba(0,174,239,.2);
  margin-top: 4px;
}
.total-l { font-size: 13px; font-weight: 700; color: #9CA3AF; text-transform: uppercase; letter-spacing: .06em; }
.total-v { font-size: 26px; font-weight: 800; color: var(--blue); }

.margin-wrap {
  margin-top: 12px;
  background: rgba(255,255,255,.04);
  border-radius: 8px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.06);
}
.margin-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #6B7280;
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.margin-track {
  height: 6px;
  background: rgba(255,255,255,.08);
  border-radius: 4px;
  overflow: hidden;
}
.margin-fill { height: 100%; border-radius: 4px; transition: width .4s ease; }
.margin-detail {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 12px;
  flex-wrap: wrap;
}
.margin-detail span { color: #6B7280; }
.margin-detail strong { color: #D1D5DB; }

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 13px 20px;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all .15s;
  letter-spacing: .01em;
  /* iPhone: proper touch target */
  min-height: 48px;
  touch-action: manipulation;
}
.btn-blue    { background: var(--blue); color: #fff; box-shadow: 0 2px 8px rgba(0,174,239,.3); }
.btn-blue:hover { background: var(--blue-dark); box-shadow: 0 4px 14px rgba(0,174,239,.4); transform: translateY(-1px); }
.btn-green   { background: #25D366; color: #fff; box-shadow: 0 2px 8px rgba(37,211,102,.3); }
.btn-green:hover { background: #1EB85A; box-shadow: 0 4px 14px rgba(37,211,102,.4); transform: translateY(-1px); }
.btn-outline { background: transparent; color: var(--blue); border: 2px solid var(--blue); }
.btn-outline:hover { background: var(--blue-light); }
.btn-sm      { padding: 6px 13px; font-size: 12px; box-shadow: none; }
.btn-sm:hover { transform: none; }
.btn-full    { width: 100%; }
.btn-grid    { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }

/* ── PANELS ─────────────────────────────────────────────────── */
.panel {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}

/* ── HISTORY ITEMS ──────────────────────────────────────────── */
.h-list, .c-list { display: flex; flex-direction: column; gap: 6px; }

.h-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border-radius: 7px;
  cursor: pointer;
  transition: background .12s;
}
.h-item:hover { background: var(--blue-light); }
.h-item .h-inv  { font-size: 11px; font-weight: 700; color: var(--blue); min-width: 82px; }
.h-item .h-cl   { flex: 1; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-item .h-dt   { font-size: 11px; color: var(--muted); white-space: nowrap; }
.h-item .h-tot  { font-size: 13px; font-weight: 700; white-space: nowrap; }
.h-item .h-del  { background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer; padding: 0 3px; border-radius: 4px; line-height: 1; }
.h-item .h-del:hover { color: var(--danger); }

/* ── CLIENT ITEMS ───────────────────────────────────────────── */
.c-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border-radius: 7px;
  cursor: pointer;
  transition: background .12s;
}
.c-item:hover { background: var(--blue-light); }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--black);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.c-item .c-name { flex: 1; font-size: 13px; font-weight: 600; }
.c-item .c-loc  { font-size: 12px; color: var(--muted); }
.c-item .c-del  { background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer; padding: 0 3px; border-radius: 4px; line-height: 1; }
.c-item .c-del:hover { color: var(--danger); }

/* ── DASHBOARD ──────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.kpi-l { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 5px; }
.kpi-v { font-size: 22px; font-weight: 800; color: var(--blue); line-height: 1.1; }
.kpi-s { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chart-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 14px;
}
.chart-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 16px; }

.bar-chart { display: flex; gap: 8px; align-items: flex-end; height: 130px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-fill { width: 100%; background: var(--blue); border-radius: 4px 4px 0 0; min-height: 3px; }
.bar-mo  { font-size: 11px; color: var(--muted); }
.bar-amt { font-size: 10px; color: var(--text); font-weight: 600; }

.hbar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.hbar-l { width: 110px; font-size: 12px; text-align: right; color: var(--text); flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-t { flex: 1; height: 18px; background: var(--surface); border-radius: 4px; overflow: hidden; }
.hbar-f { height: 100%; background: var(--blue); border-radius: 4px; }
.hbar-v { font-size: 12px; font-weight: 600; min-width: 65px; color: var(--text); }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-ico { font-size: 32px; margin-bottom: 10px; }

/* ── PRESETS ────────────────────────────────────────────────── */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 12px;
}
.pc {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  position: relative;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
}
.pc:hover { box-shadow: 0 6px 20px rgba(0,174,239,.16); transform: translateY(-1px); }
.pc-del { position: absolute; top: 10px; right: 10px; background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; line-height: 1; }
.pc-del:hover { color: var(--danger); }
.pc-name { font-size: 14px; font-weight: 700; margin-bottom: 6px; padding-right: 18px; }
.pc-meta { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.pc-tot  { margin-top: 10px; font-size: 15px; font-weight: 800; color: var(--blue); }

.pc-new {
  border: 2px dashed var(--border);
  background: transparent;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  min-height: 100px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.pc-new:hover { border-color: var(--blue); color: var(--blue); }

.hint {
  background: var(--blue-light);
  border: 1px solid #BAE3F9;
  border-radius: 8px;
  padding: 11px 15px;
  font-size: 13px;
  color: var(--blue-dark);
  margin-bottom: 14px;
}

/* ── CLIENTS VIEW ───────────────────────────────────────────── */
.section-box {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 16px;
}
.sb-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.sb-desc  { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.url-row  { display: flex; gap: 8px; margin-bottom: 10px; }
.url-row input { flex: 1; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.chip-ok  { background: #D1FAE5; color: #065F46; }
.chip-err { background: #FEE2E2; color: #991B1B; }

.code-block {
  background: #0F172A;
  color: #E2E8F0;
  border-radius: 8px;
  padding: 16px;
  font-family: 'Menlo','Monaco',monospace;
  font-size: 11.5px;
  overflow-x: auto;
  white-space: pre;
  margin-top: 10px;
}
.steps { font-size: 13px; color: var(--muted); padding-left: 18px; margin: 10px 0; line-height: 1.9; }

/* ── MISC ───────────────────────────────────────────────────── */
.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.flex-sb { display: flex; justify-content: space-between; align-items: center; }

/* ── RESPONSIVE — iPhone ────────────────────────────────────── */
@media (max-width: 700px) {

  /* Header: smaller logo, scrollable nav */
  #app-header {
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
    gap: 10px;
  }
  #header-logo { height: 30px; }

  /* Nav: scroll horizontally if needed */
  nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 2px;
    flex-shrink: 1;
    min-width: 0;
  }
  nav::-webkit-scrollbar { display: none; }
  .nav-tab { padding: 6px 11px; font-size: 12px; min-height: 44px; flex-shrink: 0; }

  /* Container: use safe areas on sides */
  .container {
    padding: 12px 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  /* Cards: less padding */
  .card { padding: 14px 14px; margin-bottom: 8px; }

  /* All grids → single column */
  .r2, .r3, .r2l { grid-template-columns: 1fr; }
  .row { gap: 8px; margin-bottom: 8px; }

  /* Stats: 2 columns */
  .stats    { grid-template-columns: 1fr 1fr; gap: 7px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Results panel */
  .results  { padding: 14px; }
  .stat-n   { font-size: 18px; }
  .total-v  { font-size: 22px; }

  /* Buttons: full width stack */
  .btn-grid { grid-template-columns: 1fr; gap: 8px; }
  .btn-full, .btn-grid .btn { font-size: 15px; min-height: 52px; }

  /* Presets: 1 column */
  .preset-grid { grid-template-columns: 1fr; }

  /* Charts */
  .hbar-l { width: 90px; font-size: 11px; }

  /* Panels */
  .panel { padding: 12px; }

  /* Internal section */
  .internal-box { padding: 12px; }

  /* History items: hide date on small screens */
  .h-item .h-dt { display: none; }

  /* Section boxes */
  .section-box { padding: 14px; }

  /* Bottom safe area for home indicator */
  #calc-extras .container { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* iPhone SE / small phones */
@media (max-width: 390px) {
  .nav-tab { font-size: 11.5px; padding: 6px 9px; }
  .stat-n  { font-size: 16px; }
  .total-v { font-size: 20px; }
}

/* Landscape iPhone */
@media (max-width: 900px) and (orientation: landscape) {
  #app-header {
    height: calc(48px + env(safe-area-inset-top));
  }
  .container { padding: 10px 16px; }
  .r2 { grid-template-columns: 1fr 1fr; }
}
