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

:root {
  --primary:   #0ea5e9;
  --primary-d: #0284c7;
  --bg:        #f0f4f8;
  --card:      #ffffff;
  --text:      #1e293b;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --radius:    12px;

  --status-utkast:     #94a3b8;
  --status-skickad:    #f59e0b;
  --status-accepterad: #3b82f6;
  --status-pagaende:   #8b5cf6;
  --status-klar:       #22c55e;
  --status-avbruten:   #ef4444;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 430px;
  margin: 0 auto;
}

/* ── SCREEN SWITCHER ── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; }

/* ── TOP BAR ── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-back {
  width: 36px; height: 36px;
  border: none; background: var(--bg);
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--muted); flex-shrink: 0;
}
.topbar h1 { font-size: 17px; font-weight: 700; flex: 1; }
.topbar-badge {
  background: var(--primary); color: white;
  font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 20px;
}
.topbar-icon {
  width: 36px; height: 36px;
  border: none; background: var(--primary);
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: white; flex-shrink: 0;
  text-decoration: none;
}
.topbar-icon-muted {
  width: 36px; height: 36px;
  border: 1px solid var(--border); background: var(--bg);
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--muted); flex-shrink: 0;
  text-decoration: none;
}
.topbar-icon-muted:hover { border-color: var(--primary); color: var(--primary); }

/* ── STATS ROW ── */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 16px;
}
.stat-card {
  background: var(--card);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
  border: 1px solid var(--border);
}
.stat-card .num { font-size: 22px; font-weight: 800; line-height: 1; }
.stat-card .lbl { font-size: 10px; color: var(--muted); margin-top: 2px; }
.stat-card.pagaende .num { color: var(--status-pagaende); }
.stat-card.skickad .num  { color: var(--status-skickad); }
.stat-card.klar .num     { color: var(--status-klar); }
.stat-card.total .num    { color: var(--primary); }

/* ── FILTER TABS ── */
.filter-tabs {
  display: flex;
  gap: 6px;
  padding: 0 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }
.tab {
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ── ORDER LIST ── */
.order-list { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }

.order-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  cursor: pointer;
  transition: box-shadow .15s;
}
.order-card:active { box-shadow: 0 0 0 2px var(--primary); }

.order-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.order-num { font-size: 12px; color: var(--muted); font-weight: 600; }
.order-name { font-size: 15px; font-weight: 700; margin-top: 1px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-utkast     { background: #f1f5f9; color: var(--status-utkast); }
.badge-skickad    { background: #fef3c7; color: #b45309; }
.badge-accepterad { background: #dbeafe; color: #1d4ed8; }
.badge-pagaende   { background: #ede9fe; color: #6d28d9; }
.badge-klar       { background: #dcfce7; color: #15803d; }
.badge-avbruten   { background: #fee2e2; color: #b91c1c; }

.order-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.order-meta span { display: flex; align-items: center; gap: 4px; }

.order-card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.assignee {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}
.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: white;
  flex-shrink: 0;
  background: var(--primary);
}

.time-tag {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  padding: 3px 8px;
  border-radius: 6px;
}
.time-tag.today { color: var(--primary); background: #e0f2fe; font-weight: 600; }
.time-tag.late  { color: #ef4444; background: #fee2e2; font-weight: 600; }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 20px;
  right: 50%;
  transform: translateX(50%);
  width: 56px; height: 56px;
  background: var(--primary);
  border-radius: 50%;
  border: none;
  box-shadow: 0 4px 16px rgba(14,165,233,.45);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  color: white;
  z-index: 200;
}

/* ── BOTTOM NAV ── */
.bottom-nav {
  background: var(--card);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  position: sticky;
  bottom: 0;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  color: var(--muted);
  padding: 4px 0;
  cursor: pointer;
  border: none;
  background: none;
}
.nav-item.active { color: var(--primary); }
.nav-item .icon { font-size: 22px; }

/* ── SECTION LABEL ── */
.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 4px 16px 6px;
}

/* ═══════════════════════════════════════════════
   SCREEN 2 — ORDER DETAIL
═══════════════════════════════════════════════ */
.detail-hero {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  padding: 20px 16px 24px;
  color: white;
}
.detail-hero .order-num { color: rgba(255,255,255,.75); font-size: 12px; }
.detail-hero .order-name { font-size: 20px; font-weight: 800; margin: 4px 0 6px; }
.detail-hero .order-addr { font-size: 13px; opacity: .85; }

.status-row {
  display: flex;
  gap: 8px;
  padding: 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.status-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 60px;
}
.status-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  position: relative;
}
.status-dot.done { background: #dcfce7; color: #15803d; }
.status-dot.current { background: var(--primary); color: white; box-shadow: 0 0 0 4px #bae6fd; }
.status-dot::after {
  content: '';
  position: absolute;
  top: 50%; left: 100%;
  width: 100%; height: 2px;
  background: var(--border);
  transform: translateY(-50%);
}
.status-step:last-child .status-dot::after { display: none; }
.status-dot.done::after { background: #86efac; }
.status-step .lbl { font-size: 9px; color: var(--muted); text-align: center; font-weight: 600; }

.info-section { padding: 0 16px 16px; }
.info-section h3 { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }

.info-grid {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.info-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; }
.info-icon { font-size: 16px; width: 24px; text-align: center; flex-shrink: 0; }
.info-label { font-size: 12px; color: var(--muted); }
.info-value { font-size: 14px; font-weight: 600; }

.action-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 16px 16px;
}
.btn {
  padding: 13px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-success { background: #22c55e; color: white; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-full { grid-column: 1 / -1; }

.time-entry-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  margin: 0 16px 10px;
}
.time-entry-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.time-big { font-size: 28px; font-weight: 800; color: var(--primary); line-height: 1; }
.time-sub { font-size: 12px; color: var(--muted); }

/* ═══════════════════════════════════════════════
   SCREEN 3 — NY ORDER
═══════════════════════════════════════════════ */
.form-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 700; color: var(--text); }
.form-group input,
.form-group textarea,
.form-group select {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  width: 100%;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.status-select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.status-pill {
  padding: 10px 6px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--card);
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.status-pill.selected { border-color: var(--primary); background: #f0f9ff; color: var(--primary); }

.scroll-content { flex: 1; overflow-y: auto; padding-bottom: 100px; }

/* ── AUTOCOMPLETE ── */
.ac-wrap { position: relative; }
.ac-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 300;
  max-height: 260px;
  overflow-y: auto;
}
.ac-dropdown.open { display: block; }
.ac-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: #f0f9ff; }
.ac-main { font-size: 14px; font-weight: 600; color: var(--text); }
.ac-sub  { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── SAVE MSG ── */
.save-msg {
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 10px;
  display: none;
}
.save-msg.ok  { background: #dcfce7; color: #15803d; }
.save-msg.err { background: #fee2e2; color: #b91c1c; }

/* ── KALENDER ── */
.kal-vy-bar { display:flex; border:1.5px solid var(--border); border-radius:8px; overflow:hidden; margin-bottom:10px; }
.kal-vy-btn { flex:1; padding:8px; border:none; font-size:13px; font-weight:700; cursor:pointer; font-family:inherit; background:var(--card); color:var(--muted); }
.kal-vy-btn.active { background:var(--primary); color:white; }
.kal-nav-bar { display:flex; align-items:center; justify-content:space-between; }
.kal-nav-btn { border:none; background:var(--bg); border-radius:8px; padding:6px 14px; font-size:20px; cursor:pointer; line-height:1; color:var(--text); }
.kal-period  { font-weight:700; font-size:15px; }

/* ── ÅTERKOPPLING ── */
.aterkopling-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.aterkopling-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.kontakt-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.kontakt-pill-info { flex: 1; min-width: 0; }
.kontakt-pill-namn { font-size: 14px; font-weight: 600; color: var(--text); }
.kontakt-pill-roll { font-weight: 400; color: var(--muted); }
.kontakt-pill-detalj { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kontakt-ta-bort {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.kontakt-ta-bort:hover { color: #b91c1c; }

.kontakt-tom {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.kontakt-lagg-till {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  margin-top: 8px;
}
.kontakt-lagg-till input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
}
.btn-add-kontakt {
  padding: 9px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-add-kontakt:hover { background: var(--primary-d); }

@media (max-width: 480px) {
  .kontakt-lagg-till {
    grid-template-columns: 1fr;
  }
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  padding: 0;
}
@media (min-width: 500px) {
  .modal-overlay { align-items: center; padding: 16px; }
}
.modal-box {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (min-width: 500px) {
  .modal-box { border-radius: 16px; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 700; margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.modal-footer {
  display: flex;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--card);
}
.modal-footer .btn { flex: 1; justify-content: center; padding: 12px; }
