/* =========================================================================
 * KoneCRM — styles. Light, high-contrast, touch-friendly.
 * ========================================================================= */
/* Brand palette follows veikonkone.fi: primary red #c5253c on white with
 * dark gray text. Variable names kept from the original blue theme so the
 * accent color flows everywhere without touching the markup. */
:root {
  --blue: #c5253c;
  --blue-dark: #9e1d30;
  --blue-light: #fbecee;
  --green: #1e7e34;
  --green-light: #e6f4ea;
  --amber: #b26a00;
  --amber-light: #fff4e0;
  --red: #b3261e;
  --red-light: #fdecea;
  --ink: #1d1d1f;
  --ink-soft: #5f6368;
  --line: #d9dde3;
  --bg: #f4f6f8;
  --card: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .12);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- top bar ---------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  color: var(--ink);
  padding: 0 16px;
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 3px solid var(--blue);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand img { height: 38px; display: block; }
.brand-loc {
  font-size: .72rem; font-weight: 800;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-soft);
  border-left: 2px solid var(--line);
  padding-left: 10px;
}

#main-nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#main-nav::-webkit-scrollbar { display: none; }

#main-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding: 8px 13px;
  border-radius: 8px;
  white-space: nowrap;
  font-size: .95rem;
  font-weight: 600;
}

#main-nav a:hover { background: var(--blue-light); color: var(--blue); }
#main-nav a.active { background: var(--blue); color: #fff; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

#user-chip {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: .85rem;
  cursor: pointer;
  white-space: nowrap;
}
#user-chip:hover { background: var(--blue-light); border-color: var(--blue); }

/* ---------- layout ---------- */

#view { padding: 20px; max-width: 1400px; margin: 0 auto; outline: none; }

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.view-head h2 { margin: 0; font-size: 1.4rem; flex: 1; min-width: 200px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 1.05rem; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* KPI cards */
.kpi { text-align: left; }
.kpi .kpi-value { font-size: 1.7rem; font-weight: 700; margin: 2px 0; }
.kpi .kpi-label { color: var(--ink-soft); font-size: .85rem; }
.kpi.good .kpi-value { color: var(--green); }
.kpi.warn .kpi-value { color: var(--amber); }
.kpi.bad .kpi-value { color: var(--red); }

/* ---------- buttons & inputs ---------- */

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: .92rem;
  cursor: pointer;
}
.btn:hover { background: var(--blue-light); border-color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: var(--red-light); }
.btn.small { padding: 4px 9px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  border: none; background: none; cursor: pointer; font-size: 1rem;
  padding: 4px 8px; border-radius: 6px; color: inherit;
}
.icon-btn:hover { background: rgba(0, 0, 0, .08); }

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
  border-color: var(--blue);
}
input[type="checkbox"] { width: auto; transform: scale(1.2); margin-right: 6px; }
textarea { resize: vertical; min-height: 70px; }

label.field { display: block; margin-bottom: 10px; font-size: .88rem; color: var(--ink-soft); }
label.field > span { display: block; margin-bottom: 4px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 4px 14px; }
.form-grid .full { grid-column: 1 / -1; }

.search-input { max-width: 320px; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  font-size: .92rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th {
  background: #f3f4f6;
  color: #374151;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover { background: var(--blue-light); }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; }
table.data td.center, table.data th.center { text-align: center; }
table.data td.right { text-align: right; }
table.data td.nowrap { white-space: nowrap; }
table.data .muted { color: var(--ink-soft); }

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.blue { background: var(--blue-light); color: var(--blue-dark); }
.badge.green { background: var(--green-light); color: var(--green); }
.badge.amber { background: var(--amber-light); color: var(--amber); }
.badge.red { background: var(--red-light); color: var(--red); }
.badge.gray { background: #eceff1; color: var(--ink-soft); }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%) scale(.92);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: #fff;
  padding: 14px 14px 14px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: min(90vw, 480px);
  font-size: .95rem;
}
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }
#toast.success { background: var(--green); }
#toast.error { background: var(--red); }
#toast .toast-close {
  border: none; cursor: pointer;
  background: rgba(255, 255, 255, .22);
  color: #fff; font-size: .9rem; font-weight: 700;
  border-radius: 8px;
  padding: 6px 10px;
  flex: none;
}
#toast .toast-close:hover { background: rgba(255, 255, 255, .35); }

/* ---------- modal ---------- */

body.modal-open { overflow: hidden; }

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 12px;
  z-index: 200;
  overflow-y: auto;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 560px;
  max-width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.modal.wide { width: 860px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 18px; max-height: 65vh; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
}

/* ---------- notes timeline (CRM) ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  border-left: 3px solid var(--blue);
  padding: 6px 12px;
  margin-bottom: 10px;
  background: var(--blue-light);
  border-radius: 0 8px 8px 0;
}
.timeline .meta { font-size: .78rem; color: var(--ink-soft); margin-bottom: 2px; }

/* ---------- calendar ---------- */

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-dow { text-align: center; font-size: .8rem; color: var(--ink-soft); font-weight: 600; padding: 4px 0; }
.cal-cell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 92px;
  padding: 6px;
  cursor: pointer;
  font-size: .8rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cal-cell:hover { border-color: var(--blue); box-shadow: var(--shadow); }
.cal-cell.other { opacity: .4; }
.cal-cell.today { border: 2px solid var(--blue); }
.cal-cell .day-num { font-weight: 700; }
.cal-cell .cal-event {
  background: var(--blue-light);
  color: var(--blue-dark);
  border-radius: 5px;
  padding: 1px 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-cell .cal-event.done { background: var(--green-light); color: var(--green); }
.cal-cell .cal-event.cancelled { background: #eceff1; color: var(--ink-soft); text-decoration: line-through; }

.cap-bar { height: 7px; border-radius: 4px; background: #e3e7ea; overflow: hidden; margin-top: auto; }
.cap-bar > div { height: 100%; }
.cap-ok > div { background: var(--green); }
.cap-warn > div { background: var(--amber); }
.cap-full > div { background: var(--red); }

.cal-blocked {
  display: inline-block;
  background: var(--red-light); color: var(--red);
  border-radius: 5px; padding: 1px 5px;
  font-size: .6rem; font-weight: 700; white-space: nowrap;
}

.cal-rush {
  display: inline-block;
  background: var(--amber-light); color: var(--amber);
  border-radius: 5px; padding: 1px 5px;
  font-size: .6rem; font-weight: 700; white-space: nowrap;
}

.cal-one {
  display: inline-block;
  background: #eceff1; color: var(--ink-soft);
  border-radius: 5px; padding: 1px 5px;
  font-size: .6rem; font-weight: 700; white-space: nowrap;
}

/* shift week-cards: days outside the shown month are dimmed */
.day-col.other-m { opacity: .35; }

/* shift views: today gets the brand highlight, past days fade out */
.day-col.today-col {
  background: var(--blue-light);
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px var(--blue);
}
.day-col.past-col { opacity: .4; }

table.team th.today-col { background: var(--blue); border-radius: 8px; }
table.team th.today-col .th-dow,
table.team th.today-col .th-date { color: #fff; }
table.team td.today-col { outline: 2px solid var(--blue); outline-offset: -2px; }
table.team td.past-col { opacity: .45; }
table.team th.past-col .th-dow, table.team th.past-col .th-date { color: #c3c9cf; }

/* multi-select service list in the booking form */
.svc-list { display: grid; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; }
.svc-list label { display: flex; align-items: center; gap: 4px; font-size: .9rem; color: var(--ink); cursor: pointer; }

/* live drive/duration summary + collapsible advanced settings in forms */
.drive-summary {
  background: var(--blue-light); border-radius: 8px; padding: 9px 12px; margin: 12px 0 4px;
  font-size: .92rem; color: var(--ink);
}
.adv-box { margin: 6px 0 4px; }
.adv-box > summary {
  cursor: pointer; color: var(--ink-soft); font-size: .88rem; font-weight: 600;
  padding: 6px 0; list-style: revert;
}
.adv-box[open] > summary { margin-bottom: 4px; }

/* ---------- työvuorot (shift roster) ---------- */

.week-card {
  border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; margin-bottom: 12px; background: var(--card);
  box-shadow: var(--shadow);
}
.week-head {
  padding: 10px 16px; background: #f8fafc;
  border-bottom: 1px solid var(--line);
  font-size: .82rem; font-weight: 700; color: #475569;
  display: flex; justify-content: space-between; align-items: center;
}
.week-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; padding: 10px; }
.day-col {
  text-align: center; padding: 8px 4px; border-radius: 12px;
  background: #f8fafc; border: 1px solid transparent;
  transition: background .12s, box-shadow .12s;
}
.day-col.weekend { background: #eef2f7; }
.day-abbr {
  font-size: .6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: #94a3b8;
}
.day-num { font-size: .82rem; font-weight: 800; color: var(--ink); margin-top: 2px; }
.day-col.weekend .day-abbr, .day-col.weekend .day-num { color: #b6c0cc; }

/* status chip inside each personal day tile */
.day-chip {
  margin-top: 8px; border-radius: 8px; padding: 5px 3px;
  font-size: .68rem; font-weight: 800; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip-on { background: #16a34a; color: #fff; }
.chip-part { background: #f59e0b; color: #fff; }
.chip-abs { background: #94a3b8; color: #fff; }
.chip-off { background: #e9eef4; color: #9aa6b2; font-weight: 700; }
.chip-none { background: transparent; color: #d3dae2; font-weight: 700; }

.day-col.editable { cursor: pointer; }
.day-col.editable:hover { background: #fff; box-shadow: 0 0 0 2px var(--blue) inset; }

.sec-label {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .12em; color: var(--ink-soft); margin: 4px 0 8px;
}

/* =========================================================================
 * Shift team grid — modern planner look (rounded chips, spacing, avatars),
 * inspired by Deputy / When I Work / Homebase week grids.
 * ========================================================================= */
table.team {
  width: 100%; border-collapse: separate; border-spacing: 4px;
  font-size: .72rem; min-width: 760px;
}
table.team th {
  padding: 5px 3px; font-size: .62rem; font-weight: 700;
  color: var(--ink-soft); text-align: center; white-space: nowrap;
}
table.team th.nh { text-align: left; padding-left: 8px; min-width: 108px; }
table.team th.wh {
  background: var(--blue-light); color: var(--blue-dark);
  border-radius: 8px; font-size: .66rem; letter-spacing: .03em; padding: 5px 4px;
}
table.team th .th-dow { display: block; font-size: .58rem; color: #94a3b8; }
table.team th .th-date { display: block; font-weight: 800; color: var(--ink); }

table.team td {
  padding: 0; text-align: center;
  height: 38px; border-radius: 8px;
  vertical-align: middle;
}
/* sticky name column with avatar */
table.team td.nc, table.team th.nh {
  position: sticky; left: 0; z-index: 2;
  background: var(--card); text-align: left;
}
table.team td.nc {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; font-weight: 600; font-size: .82rem; color: var(--ink);
  height: 38px;
}
.avatar {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  color: #fff; font-size: .66rem; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
  letter-spacing: .02em;
}
table.team td.nc .nc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* row hover: highlight the name + faint empty cells only — never recolour chips */
table.team tr:hover td.nc { background: var(--blue-light); }
table.team tr:hover td.tm-off2 { background: #e6ebf1; }
table.team tr:hover td.tm-na { background: #f4f6f9; }

/* shift chips */
table.team td.tm-on { background: #16a34a; color: #fff; font-weight: 800; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
table.team td.tm-partial { background: #f59e0b; color: #fff; font-weight: 800; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
table.team td.tm-abs { background: #94a3b8; color: #fff; font-weight: 700; }
table.team td.tm-off2 { background: #f1f5f9; color: #cbd5e1; font-weight: 600; }
table.team td.tm-na { color: #e2e8f0; background: transparent; }
table.team td .tm-time { font-size: .58rem; font-weight: 700; line-height: 1.05; margin-top: 1px; white-space: nowrap; }

table.team tr.res-row td { background: #eef2f7; font-weight: 800; font-size: .74rem; color: #475569; }
table.team tr.res-row td.nc { background: var(--card); color: var(--ink-soft); }

table.team td.tm-edit { cursor: pointer; }
table.team td.tm-edit:hover { outline: 2px solid var(--blue); outline-offset: -2px; }

/* ---------- login & loading ---------- */

.loading-screen { text-align: center; padding: 80px 20px; color: var(--ink-soft); }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-box { max-width: 380px; margin: 60px auto; }

/* ---------- offer print ---------- */

#print-area { display: none; }

@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; font-size: 12pt; color: #000; }
  #print-area .offer-doc { max-width: 100%; }
}

.offer-doc { font-family: "Segoe UI", sans-serif; line-height: 1.45; }
.offer-doc h1 { font-size: 1.4rem; margin-bottom: 4px; }
.offer-doc table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.offer-doc th, .offer-doc td { border: 1px solid #999; padding: 6px 8px; text-align: left; font-size: .92rem; }
.offer-doc th { background: #eee; }
.offer-doc td.num, .offer-doc th.num { text-align: right; }
.offer-doc .totals td { font-weight: 600; }
.offer-doc .doc-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }

/* ---------- misc ---------- */

.muted { color: var(--ink-soft); }
.right { text-align: right; }
.mt { margin-top: 14px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
hr.soft { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- bottom navigation & mobile helpers ---------- */

#bottom-nav { display: none; }

/* delivery count chip in calendar cells — only shown on mobile */
.cal-count {
  display: none;
  background: var(--blue); color: #fff;
  border-radius: 10px; padding: 1px 7px;
  font-size: .66rem; font-weight: 700;
  width: fit-content;
}

.menu-list { display: grid; gap: 10px; }
.menu-list .menu-item {
  padding: 15px 16px; font-size: 1.05rem; text-align: left; width: 100%;
}

/* =========================================================================
 * Mobile (≤ 720px): bottom tab bar, full-screen dialogs, bigger touch
 * targets, condensed tables & calendar. Desktop layout is untouched.
 * ========================================================================= */
@media (max-width: 720px) {
  /* navigation: hide top tabs, show bottom bar */
  #main-nav { display: none; }
  #topbar { height: 52px; }
  .brand { flex: 1; }
  .brand img { height: 28px; }
  .brand-loc { font-size: .62rem; padding-left: 8px; letter-spacing: .12em; }
  #user-chip { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }

  #bottom-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--card);
    border-top: 1px solid var(--line);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .1);
    z-index: 100;
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
  }
  #bottom-nav a, #bottom-nav .more-btn {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 2px;
    border: none; background: none; text-decoration: none; cursor: pointer;
    color: var(--ink-soft); font-size: .62rem; font-weight: 600;
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
  }
  .bn-ico { font-size: 1.3rem; line-height: 1.1; }
  #bottom-nav .active { color: var(--blue-dark); background: var(--blue-light); }

  #view { padding: 12px 10px calc(88px + env(safe-area-inset-bottom)); }
  .view-head h2 { font-size: 1.15rem; }
  .view-head .btn { flex: 1 1 45%; }
  .view-head .search-input, .view-head > select, .view-head > input { max-width: 100%; flex: 1 1 100%; }

  /* touch targets & density */
  .btn { padding: 11px 14px; }
  .btn.small { padding: 7px 10px; }
  table.data th, table.data td { padding: 10px 8px; }
  .card { padding: 13px; }
  .grid { gap: 12px; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .kpi .kpi-value { font-size: 1.35rem; }

  /* hide lower-priority table columns on small screens */
  .hide-m { display: none !important; }

  /* full-screen dialogs */
  #modal-overlay { padding: 0; align-items: stretch; }
  .modal, .modal.wide {
    width: 100%; max-width: 100%; min-height: 100%;
    border-radius: 0;
    display: flex; flex-direction: column;
  }
  .modal-body { max-height: none; flex: 1; }
  .modal-foot {
    position: sticky; bottom: 0; background: var(--card);
    flex-wrap: wrap;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .modal-foot .btn { flex: 1 1 40%; padding: 12px; }

  /* calendar: compact cells, event texts → count chip */
  .cal-grid { gap: 3px; }
  .cal-cell { min-height: 56px; padding: 4px 3px; border-radius: 6px; gap: 3px; }
  .cal-cell .cal-event { display: none; }
  .cal-cell .cal-count { display: inline-block; }
  .cal-blocked-text { display: none; }
  .cal-blocked { padding: 1px 4px; }
}
