:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --ink: #1f2933;
    --muted: #6b7280;
    --line: #e3e8ee;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warn: #d97706;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: 0 24px;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-logo { height: 26px; width: auto; display: block; }
.brand-erp {
    font-weight: 700; font-size: 13px; letter-spacing: .12em;
    color: var(--muted); text-transform: uppercase;
    border-left: 1px solid var(--line); padding-left: 8px;
}
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a {
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--muted);
    font-weight: 500;
}
.mainnav a:hover { background: var(--bg); text-decoration: none; }
.mainnav a.active { color: var(--primary); background: #eef2ff; }
.userbox { display: flex; align-items: center; gap: 12px; color: var(--muted); }

/* Layout */
.container { max-width: 1080px; margin: 24px auto; padding: 0 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 24px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 18px; }

/* Kortin oikean yläkulman toiminto (esim. Poista tehtävä) */
.card.task-card { position: relative; }
.card-corner-action { position: absolute; top: 12px; right: 12px; margin: 0; }
.card-corner-action + h2, .card-corner-action + p { padding-right: 140px; }
.task-title { margin: 0 0 10px; font-size: 19px; }
.task-site { margin: -4px 0 12px; font-size: 14px; color: var(--muted); }
.task-site a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* Buttons */
.btn, button.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.3;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.95); }
.btn-danger-link, .btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-link { color: var(--primary); font-weight: 500; }
button.link {
    background: none; border: none; color: var(--muted); cursor: pointer;
    padding: 0; font: inherit; text-decoration: underline;
}
.inline { display: inline; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Forms */
label { display: block; margin-bottom: 12px; font-weight: 500; font-size: 14px; }
input, select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    margin-top: 4px;
    background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 140px; }
.form-row > .field-narrow { flex: 0 1 200px; }
.form-inline { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-inline label { margin-bottom: 0; }

/* Haettava asiakasvalinta */
.customer-combo { position: relative; margin-top: 4px; }
.customer-combo > select {
    position: absolute !important;
    width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}
.customer-combo-input {
    width: 100%;
    margin-top: 0;
}
.customer-combo-list {
    position: absolute; z-index: 40; left: 0; right: 0; top: 100%;
    max-height: 240px; overflow: auto;
    margin: 4px 0 0; padding: 4px 0;
    list-style: none;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}
.customer-combo-list li {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
}
.customer-combo-list li:hover,
.customer-combo-list li.is-selected { background: #eff6ff; }
.customer-combo-list li.is-new { color: var(--primary); font-weight: 600; }
.customer-combo-list li.is-empty {
    cursor: default; color: var(--muted); font-style: italic;
}
.customer-combo-list li.is-empty:hover { background: transparent; }
.customer-list-filter { max-width: 320px; margin-bottom: 12px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-billed { opacity: .55; }
.timer-dot { margin-left: 4px; color: var(--warn); font-size: 13px; }
.entry-edit { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.ee-form { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.entry-edit label { margin: 0; font-size: 12px; }
.entry-edit input { margin-top: 2px; }
.ee-narrow { width: 62px; }
.ee-narrow input { width: 62px; }
.ee-grow input { min-width: 200px; }
.customer-row { display: flex; gap: 10px; align-items: center; }
.customer-edit { display: flex; gap: 8px; align-items: center; flex: 1; max-width: 480px; }
.customer-edit input { margin-top: 0; }
.task-edit { margin: 4px 0 12px; }
.task-edit summary { display: inline-block; }
.entry-list { list-style: none; margin: 6px 0 0; padding: 0; }
.entry-list li { font-size: 12.5px; color: var(--muted); padding: 1px 0; }
.entry-list .entry-date { display: inline-block; min-width: 78px; }
.entry-list .entry-time { font-variant-numeric: tabular-nums; margin-right: 8px; }
.entry-list .entry-user { opacity: .8; }
.entry-list .entry-desc { color: var(--ink); opacity: .75; }
tr.js-row-link { cursor: pointer; }
tr.js-row-link:hover td { background: #f9fafb; }

/* Badges */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.badge-uusi { background: #eef2ff; color: #3730a3; }
.badge-kaynnissa, .badge-running { background: #fef3c7; color: #92400e; }
.badge-valmis { background: #dcfce7; color: #166534; }
.badge-laskutettu { background: #e5e7eb; color: #374151; }
.badge-paused { background: #e5e7eb; color: #374151; }
.badge-quote-avoin { background: #eef2ff; color: #3730a3; }
.badge-quote-hyvaksytty { background: #dcfce7; color: #166534; }
.badge-quote-hylatty { background: #fee2e2; color: #991b1b; }

/* Stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
}
.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat-num { font-size: 28px; font-weight: 700; }
.stat-lbl { color: var(--muted); font-size: 13px; }

/* Timer widget */
.timer-widget { border-left: 4px solid var(--warn); }
.timer-head { display: flex; align-items: center; gap: 10px; }
.timer-label { font-weight: 600; color: var(--warn); }
.timer-task { margin: 8px 0; color: var(--muted); }
.timer-clock { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 8px 0 16px; }
.timer-stop-form { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.timer-stop-form input { margin-top: 0; max-width: 420px; }
.timer-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Kelluva ajastinbanneri (kaikilla sivuilla kun ajastin aktiivinen) */
.timer-banner {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-left: 4px solid var(--warn);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .18);
    padding: 12px 16px;
    max-width: calc(100vw - 40px);
}
.timer-banner.is-paused { border-left-color: var(--muted); }
.timer-banner .tb-clock {
    font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
    letter-spacing: .02em;
}
.timer-banner .tb-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.timer-banner .tb-state { font-size: 11px; font-weight: 600; color: var(--warn); text-transform: uppercase; letter-spacing: .04em; }
.timer-banner.is-paused .tb-state { color: var(--muted); }
.timer-banner .tb-task { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer-banner .tb-task strong { color: var(--ink); }
.timer-banner .tb-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timer-banner .tb-stop { display: flex; align-items: center; gap: 6px; }
.timer-banner .tb-selite { width: 140px; margin-top: 0; padding: 6px 9px; font-size: 13px; }

@media (max-width: 560px) {
    .timer-banner { right: 12px; left: 12px; bottom: 12px; }
    .timer-banner .tb-task { max-width: 40vw; }
}

/* Login */
body.login-page { background: linear-gradient(160deg, #eef2f7 0%, #e2e8f0 100%); }
.login-wrap {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 24px;
}
.login-card {
    width: 100%; max-width: 380px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .12);
    padding: 36px 32px;
}
.login-brand {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin-bottom: 6px;
}
.login-brand img { height: 40px; width: auto; }
.login-erp {
    font-weight: 700; font-size: 15px; letter-spacing: .14em; text-transform: uppercase;
    color: var(--muted); border-left: 1px solid var(--line); padding-left: 10px;
}
.login-sub { text-align: center; color: var(--muted); margin: 0 0 24px; }
.login-card label { margin-bottom: 16px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; margin-top: 4px; }

/* Alavälilehdet (kuukausilaskutus) */
.subtabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.subtabs a {
    padding: 8px 14px; color: var(--muted); font-weight: 500;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subtabs a:hover { color: var(--ink); text-decoration: none; }
.subtabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Group headers (completed / subscriptions) */
.group-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin: 24px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--line);
}
.group-head h3 { margin: 0; font-size: 16px; }
.group-total { font-weight: 700; }
.group-total.all-billed { color: var(--success); }

/* Lisätiedot omalla rivillään tilausrivin alla */
.table tr.has-notes > td { border-bottom: none; padding-bottom: 2px; }
.table tr.notes-row > td {
    padding-top: 0; padding-bottom: 12px;
    white-space: normal; word-break: break-word;
}
.table tr.notes-row .notes-box {
    display: block;
    background: #fffaeb;
    border-left: 3px solid var(--warn);
    border-radius: 0 6px 6px 0;
    padding: 7px 10px;
    color: var(--ink);
    font-size: 14px;
}
.table tr.notes-row .notes-label {
    font-weight: 700; color: var(--warn);
    text-transform: uppercase; letter-spacing: .04em; font-size: 11px;
    margin-right: 6px;
}

/* Kuukausilaskutuksen kokonaissumma (ylhäällä) */
.total-summary {
    display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
    border-left: 4px solid var(--primary);
}
.total-summary .ts-label { font-weight: 600; color: var(--muted); }
.total-summary .ts-amount { font-size: 26px; font-weight: 700; color: var(--ink); }

/* Avoimet tehtävät kuukausilaskutusryhmän alla */
.open-tasks {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed var(--line);
}
.open-tasks-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 8px;
}
.open-tasks-label {
    font-weight: 700; font-size: 12px; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em;
}
.open-tasks-list {
    list-style: none; margin: 0; padding: 0;
    display: flex; flex-direction: column; gap: 6px;
}
.open-tasks-list li {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    font-size: 14px;
}
.open-tasks-list a { color: var(--ink); text-decoration: none; }
.open-tasks-list a:hover { text-decoration: underline; color: var(--primary); }

@media (max-width: 720px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .mainnav { overflow-x: auto; }
    .topbar { gap: 12px; padding: 0 12px; }
}

/* WYSIWYG-editori (assets/editor.js) */
.field { margin-bottom: 12px; }
.field-label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 14px; }
.wysiwyg { margin-bottom: 12px; position: relative; }
.wysiwyg-toolbar {
    display: flex; flex-wrap: wrap; gap: 4px;
    border: 1px solid var(--line); border-bottom: none;
    border-radius: 8px 8px 0 0; background: #f9fafb; padding: 6px;
}
.wysiwyg-btn {
    background: #fff; border: 1px solid var(--line); border-radius: 6px;
    padding: 3px 9px; font-size: 13px; line-height: 1.4; color: var(--ink); cursor: pointer;
}
.wysiwyg-btn:hover { background: var(--bg); }
.wysiwyg-area {
    border: 1px solid var(--line); border-radius: 0 0 8px 8px;
    background: #fff; padding: 10px 12px; min-height: 160px;
    font-size: 15px; line-height: 1.5; overflow-wrap: break-word;
}
.wysiwyg-area:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.wysiwyg-area > :first-child { margin-top: 0; }
.wysiwyg-area > :last-child { margin-bottom: 0; }
.wysiwyg.is-ready > textarea { display: none; }
.wysiwyg-area.is-dragover { outline: 2px dashed var(--primary); outline-offset: -2px; background: #f5f9ff; }
.wysiwyg-area img { max-width: 100%; height: auto; border-radius: 6px; margin: 6px 0; }
.wysiwyg-status { margin: 6px 0 0; }
.wysiwyg-status.is-error { color: var(--danger); }

/* Kuvan koon muuttaminen editorissa */
.wysiwyg-area img.wysiwyg-selected { outline: 2px solid var(--primary); outline-offset: 2px; }
.wysiwyg-handle {
    position: absolute; width: 16px; height: 16px; z-index: 2;
    background: #fff; border: 2px solid var(--primary); border-radius: 3px;
    cursor: nwse-resize; touch-action: none;
}

/* Tehtävän kuvaus (tallennettu HTML) */
.task-description > :first-child { margin-top: 0; }
.task-description > :last-child { margin-bottom: 0; }
.task-description ul, .task-description ol { padding-left: 22px; }
.task-description img { max-width: 100%; height: auto; border-radius: 6px; margin: 8px 0; display: block; }

/* Raportit */
.report-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.report-period { margin-left: 8px; font-size: 15px; }
.report-filter label { margin: 0; display: flex; align-items: center; gap: 8px; }
.report-filter select { width: auto; min-width: 160px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.report-table th, .report-table td { padding: 8px 10px; white-space: nowrap; }
.report-table th.num, .report-table td.num { min-width: 56px; }
.report-table .report-sub { display: block; font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 11px; }
.report-table .is-weekend { background: #f9fafb; color: var(--muted); }
.report-table .is-today { background: #eff6ff; }
.report-table th.is-today { color: var(--primary); }
.report-table tfoot th { border-top: 2px solid var(--line); color: var(--ink); font-size: 13px; }
.report-table .report-task { white-space: normal; min-width: 220px; }
.report-table .report-task .muted { display: block; line-height: 1.2; }
.report-table .has-notes-tip { cursor: help; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }

/* Valmiit-listan sivustosarake: kapea ja rivin yläreunaan (tehtäväsolussa on kirjauslista) */
.table td.site-cell { vertical-align: top; max-width: 200px; word-break: break-word; }
