:root {
  --bg: #eceef1;
  --card: #ffffff;
  --border: #d3d7dd;
  --text: #24282e;
  --muted: #6b717a;
  --head: #3c4148;
  --accent: #5a6069;
  --accent-hover: #43484f;
  --focus: rgba(90, 96, 105, 0.25);
  --error-bg: #fdecec;
  --error-text: #a12626;
  --error-border: #f3c4c4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

/* Kirjautuminen */
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 28px 28px;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 4px solid var(--head);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}
.login-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--head);
}
.login-sub {
  margin: 4px 0 22px;
  color: var(--muted);
  font-size: 14px;
}
.login-card label {
  display: block;
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--head);
}
.login-card input[type=text],
.login-card input[type=password] {
  display: block;
  width: 100%;
  margin: 0 0 16px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
  background: #fff;
}
.login-card button {
  width: 100%;
  margin-top: 6px;
  padding: 11px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.login-card button:hover { background: var(--accent-hover); }
.login-card button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.login-error {
  margin: 0 0 18px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--error-text);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 6px;
}

/* Kirjautuneen käyttäjän sivut */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background-color: var(--head);
  color: #fff;
}
.topbar .title { font-weight: 700; letter-spacing: 0.08em; color: #fff; text-decoration: none; }
.topbar .user { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.topbar form { margin: 0; }
.topbar button {
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: #fff;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  cursor: pointer;
}
.topbar button:hover { background: rgba(255, 255, 255, 0.12); }
.content {
  max-width: 1200px;
  margin: 24px auto;
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.content h1 { margin-top: 0; font-size: 22px; color: var(--head); }

@media (max-width: 600px) {
  .topbar { padding: 10px 16px; }
  .content { margin: 16px; padding: 16px; }
}

/* Kanavavalinta */
.muted { color: var(--muted); }
.breadcrumb { margin: 0 0 12px; font-size: 14px; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.ch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.ch-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  color: var(--text);
  text-decoration: none;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  transition: box-shadow 0.15s, border-color 0.15s, background 0.15s;
}
.ch-card:hover, .ch-card:focus-visible {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
.ch-name { font-weight: 600; color: var(--head); }
.ch-meta { font-size: 13px; color: var(--muted); }

/* Kanavaraportti */
.content h2 { margin: 28px 0 10px; font-size: 17px; color: var(--head); }
.range-form, .list-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
  margin: 8px 0 6px;
}
.range-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--head); }
.range-form input, .list-form input, .list-form select {
  padding: 7px 9px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.list-form input[type=search] { flex: 1 1 220px; max-width: 360px; }
.range-form input:focus, .list-form input:focus, .list-form select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); background: #fff;
}
.range-form button, .list-form button {
  padding: 8px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.range-form button:hover, .list-form button:hover { background: var(--accent-hover); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets a {
  padding: 6px 10px;
  font-size: 13px;
  color: var(--head);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
}
.presets a:hover { border-color: var(--accent); }
.presets a.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.range-label { margin: 10px 0 0; font-size: 14px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--head); }
.kpi-sub { font-size: 12px; line-height: 1.5; color: var(--muted); }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 160px;
  padding: 6px 0 0;
  border-bottom: 1px solid var(--border);
}
.chart .bar {
  flex: 1 1 0;
  min-width: 2px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.chart .bar.weekend { background: #f3f4f6; }
.chart .seg { display: block; width: 100%; }
.seg.ans, .sw.ans { background: var(--accent); }
.seg.unans, .sw.unans { background: #d9a441; }
.chart-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.chart-legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; margin-top: 6px; }
.chart-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-left: 8px; }
.chart-legend .sw:first-child { margin-left: 0; }

.table-wrap { overflow-x: auto; }
table.calls { width: 100%; border-collapse: collapse; font-size: 14px; }
table.calls th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
}
table.calls td { padding: 9px 10px; border-bottom: 1px solid #eceef1; vertical-align: top; }
table.calls tr:hover td { background: #fafbfc; }
table.calls .num { text-align: right; white-space: nowrap; }
table.calls .nowrap { white-space: nowrap; }
table.calls .summary { min-width: 280px; max-width: 560px; }
table.calls details summary { cursor: pointer; list-style: none; }
table.calls details summary::after { content: " Näytä kaikki"; color: var(--accent); font-weight: 600; font-size: 13px; }
table.calls details[open] summary { display: none; }
.status { display: inline-block; padding: 2px 8px; font-size: 12px; border-radius: 999px; white-space: nowrap; background: #eceef1; }
.status-answered { background: #e3efe5; color: #2c6b37; }
.status-noanswer, .status-abandon { background: #fbefd9; color: #8a5a00; }
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 16px; font-size: 14px; }
.pager a { color: var(--accent); font-weight: 600; text-decoration: none; }
.pager a:hover { text-decoration: underline; }

/* Yhteydenottojen aiheet */
.small { font-size: 13px; }
.topic-bars { display: flex; flex-direction: column; gap: 4px; max-width: 760px; }
.topic-row {
  display: grid;
  grid-template-columns: minmax(120px, 260px) 1fr 44px;
  align-items: center;
  gap: 12px;
  padding: 5px 8px;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
}
.topic-row:hover, .topic-row:focus-visible { outline: none; background: #f3f4f6; }
.topic-row.active { background: #e6e8eb; font-weight: 600; }
.topic-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-track { height: 12px; background: #eceef1; border-radius: 6px; overflow: hidden; }
.topic-fill { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.topic-num { text-align: right; font-size: 14px; font-weight: 600; color: var(--head); }
.chip-row { margin: 4px 0; font-size: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px; background: #e6e8eb; border-radius: 999px; font-weight: 600; }
.chip a { color: var(--head); text-decoration: none; font-size: 16px; line-height: 1; padding: 0 4px; }
@media (max-width: 600px) {
  .topic-row { grid-template-columns: 1fr 70px 36px; }
}

/* Ruuhkaisin tunti */
.peak-text { margin: 0 0 4px; }
.chart-labeled { padding-top: 20px; }
.chart-hours { height: 140px; gap: 6px; }
.chart-labeled .bar-num {
  display: block;
  margin-bottom: 3px;
  text-align: center;
  font-size: 12px;
  line-height: 14px;
  color: var(--muted);
}
.chart-hours .bar.peak .bar-num { color: var(--head); font-weight: 700; }
.chart-labels { justify-content: stretch; gap: 2px; }
.chart-labels span { flex: 1 1 0; min-width: 0; text-align: center; overflow: hidden; }
.chart-labels span.weekend { color: #9aa0a8; }
.chart-hours-axis { gap: 6px; }
@media (max-width: 700px) {
  .chart-labeled:not(.chart-hours) .bar-num, .chart-labels:not(.chart-hours-axis) span { font-size: 9px; }
}
