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

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --orange: #f97316;
  --blue: #3b82f6;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 16px;
}

/* ── Header ── */
.header {
  background: var(--primary);
  color: white;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(99,102,241,.25);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-left { display: flex; flex-direction: column; }
.header-title { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.header-sub { font-size: 0.78rem; opacity: 0.8; margin-top: 1px; }
.header-right { display: flex; gap: 8px; align-items: center; }

/* ── Container ── */
.container { max-width: 520px; margin: 0 auto; padding: 24px 16px 48px; }
.container-wide { max-width: 680px; margin: 0 auto; padding: 24px 16px 48px; }

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ── Form ── */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
input[type=text], input[type=number], input[type=password] {
  width: 100%;
  padding: 11px 14px;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
input[readonly] { background: #f8fafc; color: var(--muted); cursor: default; }
input::placeholder { color: #cbd5e1; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 20px;
  font-size: 0.95rem; font-weight: 600;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .08s, border-color .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 14px rgba(99,102,241,.35); }
.btn-primary:disabled { background: #a5b4fc; cursor: default; transform: none; box-shadow: none; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; box-shadow: 0 4px 14px rgba(16,185,129,.3); }
.btn-success:disabled { background: #6ee7b7; cursor: default; transform: none; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-danger:disabled { background: #fca5a5; cursor: default; transform: none; }
.btn-ghost { background: transparent; color: var(--primary); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--primary); background: #eef2ff; }
.btn-white { background: white; color: var(--primary); border-color: white; }
.btn-white:hover { background: #eef2ff; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; border-radius: 6px; }
.btn-xs { padding: 4px 10px; font-size: 0.78rem; border-radius: 5px; }

/* ── Messages ── */
.msg { padding: 11px 14px; border-radius: 8px; font-size: 0.9rem; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.msg-error { background: #fef2f2; color: #b91c1c; border: 1.5px solid #fecaca; }
.msg-ok { background: #f0fdf4; color: #166534; border: 1.5px solid #bbf7d0; }
.msg-warn { background: #fffbeb; color: #92400e; border: 1.5px solid #fde68a; }

/* ── List items ── */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  transition: border-color .15s, box-shadow .15s;
}
.list-item:hover { border-color: #c7d2fe; box-shadow: var(--shadow); }
.list-item-name { font-weight: 600; flex: 1; }
.list-item-meta { font-size: 0.83rem; color: var(--muted); margin-top: 2px; }

/* ── Status dot ── */
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: var(--success); }
.dot-orange { background: var(--orange); }
.dot-blue { background: var(--blue); }
.dot-gray { background: #94a3b8; }
.dot-light { background: #e2e8f0; }

/* ── Badge ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ── Inline row ── */
.row { display: flex; gap: 8px; align-items: center; }
.row-wrap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Divider ── */
.divider { border: none; border-top: 1.5px solid var(--border); margin: 20px 0; }

/* ── Links ── */
.link-group { display: flex; flex-direction: column; gap: 4px; margin-top: 20px; }
a.nav-link {
  display: block; text-align: center;
  color: var(--primary); text-decoration: none;
  font-size: 0.9rem; font-weight: 500;
  padding: 8px;
  border-radius: 6px;
  transition: background .12s;
}
a.nav-link:hover { background: #eef2ff; }

/* ── Big nav buttons ── */
.big-btn {
  display: block; padding: 18px 20px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none; color: var(--text);
  font-weight: 700; font-size: 1rem;
  transition: border-color .15s, box-shadow .15s, background .15s;
  margin-bottom: 12px;
}
.big-btn:hover { border-color: var(--primary); box-shadow: var(--shadow-md); background: #fafbff; }
.big-btn span { display: block; font-size: 0.82rem; color: var(--muted); font-weight: 400; margin-top: 3px; }

/* ── Drag handle ── */
.drag-handle { color: #cbd5e1; font-size: 1.2rem; cursor: grab; user-select: none; flex-shrink: 0; }

/* ── Status cards (tilanne) ── */
.status-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-radius: 10px;
  border-left: 4px solid transparent;
  margin-bottom: 8px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.status-card.rastilla-oma { border-left-color: var(--success); background: #f0fdf4; }
.status-card.tulossa { border-left-color: var(--orange); background: #fff7ed; }
.status-card.rastilla-muu { border-left-color: var(--blue); background: #eff6ff; }
.status-card.matkalla { border-left-color: #94a3b8; }
.status-card.ei-aloitettu { border-left-color: var(--border); opacity: .6; }
.status-card-info { flex: 1; min-width: 0; }
.status-card-name { font-weight: 700; font-size: 0.97rem; }
.status-card-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

/* ── QR card ── */
.qr-card { display: inline-block; border: 2px solid var(--text); border-radius: var(--radius); padding: 20px 24px; text-align: center; }
.qr-card h3 { font-size: 1.2rem; margin-bottom: 4px; }
.qr-card p { color: var(--muted); font-size: 0.88rem; margin-bottom: 14px; }

/* ── Toggle buttons ── */
.toggle-group { display: flex; gap: 0; border: 2px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 16px; }
.toggle-btn { flex: 1; padding: 10px; font-size: 0.92rem; font-weight: 600; background: white; border: none; cursor: pointer; transition: background .15s, color .15s; color: var(--muted); }
.toggle-btn.active { background: var(--primary); color: white; }

/* ── Autocomplete ── */
.ac-wrap { position: relative; }
.ac-list {
  position: absolute; z-index: 100; width: 100%;
  background: white; border: 2px solid var(--primary);
  border-top: none; border-radius: 0 0 8px 8px;
  max-height: 220px; overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.ac-list div { padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-size: 0.93rem; }
.ac-list div:hover, .ac-list div.active { background: #eef2ff; }
.ac-list .ac-sub { font-size: 0.78rem; color: var(--muted); }

/* ── Rasti inline edit ── */
.siirtyma-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 52px;
  font-size: 0.82rem; color: var(--muted);
}
.siirtyma-row input { width: 56px; padding: 4px 8px; font-size: 0.82rem; border: 1.5px solid var(--border); border-radius: 6px; margin-bottom: 0; }

/* ── Print ── */
@media print {
  .header, .no-print, a.nav-link, .btn:not(.print-show) { display: none !important; }
  body { background: white; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

/* ── Active vartio list ── */
.active-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.active-item-info { flex: 1; }
.active-item-name { font-weight: 700; font-size: 0.95rem; }
.active-item-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

/* ── Tulossa alert ── */
.alert-orange {
  background: #fff7ed;
  border: 2px solid var(--orange);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.alert-orange-title { font-weight: 700; color: #c2410c; font-size: 0.9rem; margin-bottom: 8px; }
.alert-item { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-size: 0.9rem; border-bottom: 1px solid #fed7aa; }
.alert-item:last-child { border-bottom: none; }
.alert-item-time { font-weight: 700; color: #c2410c; }

/* ── Ohje-modal ── */
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:1000; display:flex; align-items:center; justify-content:center; padding:16px; }
.modal-overlay.hidden { display:none; }
.modal-box { background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow-md); max-width:480px; width:100%; max-height:85vh; overflow-y:auto; }
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:18px 20px 0; }
.modal-title { font-weight:700; font-size:1.05rem; }
.modal-close { background:none; border:none; font-size:1.4rem; cursor:pointer; color:var(--muted); line-height:1; padding:4px; }
.modal-body { padding:16px 20px 20px; font-size:.9rem; color:var(--text); }
.modal-body h3 { font-size:.8rem; font-weight:700; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); margin:14px 0 6px; }
.modal-body h3:first-child { margin-top:0; }
.modal-body ul { padding-left:18px; }
.modal-body li { margin-bottom:5px; line-height:1.5; }
.modal-body p { margin-bottom:8px; line-height:1.5; }
.btn-help { background:rgba(255,255,255,.2); border:1.5px solid rgba(255,255,255,.5); color:#fff; border-radius:999px; width:32px; height:32px; font-size:.95rem; font-weight:700; cursor:pointer; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.btn-help:hover { background:rgba(255,255,255,.35); }

/* ── Data table ── */
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { text-align: left; padding: 10px 12px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom: 2px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.td-badge { text-align: center; }
