/* Saia — spec §10 sitova. Suorat kulmat, ei ikoneita, ei pillereitä, hairline-viivat. */
:root {
    --bg:      #F7F7F4;
    --surface: #FFFFFF;
    --bg-alt:  #ECECE7;
    --ink:     #1C1C1A;
    --muted:   #74746D;
    --oak:     #B08A5A;
    --hair:    #DCDCD5;
    --danger:  #B04A42;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
html { color-scheme: light; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font);
    font-weight: 400;
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Typografia */
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.kicker {
    font-size: 13px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 500;
}
.meta { font-size: 13px; color: var(--muted); }
.text-oak { color: var(--oak); }
.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.strong { font-weight: 650; color: var(--ink); }

/* Linkit — vain oak-korostus, ei alleviivausta paitsi hover */
a { color: var(--oak); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
a:focus-visible { outline: 2px solid var(--oak); outline-offset: 2px; }

/* App-layout: vasen 240 px + oikea sisältö */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
    display: flex;
    flex-direction: column;
    padding: 40px 24px 24px;
    border-right: 1px solid var(--hair);
    background: var(--surface);
    min-height: 100vh;
    box-sizing: border-box;
}
.sidebar nav { flex: 1; }
.sidebar-brand {
    font-size: 17px;
    font-weight: 650;
    color: var(--ink);
    margin-bottom: 40px;
    letter-spacing: -0.01em;
}
.sidebar nav a {
    display: block;
    padding: 8px 0;
    font-size: 15px;
    color: var(--ink);
    font-weight: 400;
}
.sidebar nav a.active {
    font-weight: 650;
    color: var(--oak);
}
.sidebar nav a:hover { text-decoration: none; color: var(--oak); }
.sidebar .foot {
    margin-top: 24px;
    padding-top: 16px;
    font-size: 13px;
    color: var(--muted);
    border-top: 1px solid var(--hair);
}
.sidebar .foot a { color: var(--muted); }

.main { padding: 40px 64px; max-width: 1100px; width: 100%; }
.main > .kicker { margin-bottom: 8px; }
.main > h1 { margin-bottom: 24px; }

/* Napit — suorakulmaiset, 40 px korkeat */
.btn {
    display: inline-block;
    height: 40px;
    padding: 0 24px;
    font-family: var(--font);
    font-size: 15px;
    font-weight: 500;
    line-height: 40px;
    text-align: center;
    border: 1px solid var(--ink);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
    transition: none;
}
.btn:hover { text-decoration: none; background: var(--bg-alt); }
.btn:focus-visible { outline: 2px solid var(--oak); outline-offset: 2px; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #000; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--bg-alt); }

/* Lomakekentät */
.field { margin-bottom: 24px; }
.field label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
}
.field input, .field textarea, .field select {
    width: 100%;
    padding: 8px 12px;
    height: 40px;
    font-family: var(--font);
    font-size: 15px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: 0;
    outline: none;
}
.field textarea { height: auto; padding: 12px; line-height: 1.55; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--ink); }
.field .error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* Login-näkymä */
.login-wrap {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}
.login-card {
    background: var(--surface);
    padding: 40px;
    max-width: 400px;
    width: 100%;
    border: 1px solid var(--hair);
}
.login-card h1 { margin-bottom: 24px; }

/* Taulukot/listat — hairline-viivat, ei zebraa */
.list { width: 100%; border-collapse: collapse; }
.list th, .list td {
    text-align: left;
    padding: 16px 12px;
    border-bottom: 1px solid var(--hair);
}
.list th {
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    padding-top: 0;
    padding-bottom: 12px;
}
.list tr { height: 56px; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--bg-alt); }
.list tbody tr:focus-within { outline: 2px solid var(--oak); outline-offset: -2px; }

/* Tilat tekstinä (ei pillereinä) */
.state-draft   { color: var(--oak);   font-weight: 500; }
.state-awaits  { color: var(--ink);   font-weight: 650; }
.state-handled { color: var(--muted); font-weight: 400; }
.state-esc     { color: var(--danger); font-weight: 500; }

/* Välilehdet — tekstiriviä + 2 px oak-alaviiva aktiiviselle */
.tabs { display: flex; gap: 40px; border-bottom: 1px solid var(--hair); margin-bottom: 24px; }
.tabs a {
    display: block;
    padding: 8px 0;
    font-size: 15px;
    color: var(--ink);
    text-decoration: none;
}
.tabs a.active { font-weight: 650; box-shadow: inset 0 -2px 0 var(--oak); }

/* Ticket-näkymä: 1fr + 380 px sivupaneeli */
.ticket-grid { display: grid; grid-template-columns: 1fr 380px; gap: 40px; }
.thread { display: flex; flex-direction: column; gap: 16px; }
.msg {
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--hair);
}
.msg .who {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
}
.msg .body { white-space: pre-wrap; }
.msg.out { background: var(--bg-alt); }

/* AI-luonnos paneeli */
.draft {
    background: var(--bg-alt);
    padding: 24px;
    border-left: 2px solid var(--oak);
}
.draft h2 { margin-bottom: 16px; }
.draft textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    border: 1px solid var(--hair);
    border-radius: 0;
    background: var(--surface);
    resize: vertical;
}
.draft .actions { display: flex; gap: 16px; margin-top: 16px; }
.draft .sources { margin-top: 16px; font-size: 13px; color: var(--muted); }

/* Toast — alareunan yksirivinen ink-palkki */
.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: var(--ink);
    color: #fff;
    padding: 12px 24px;
    font-size: 15px;
    opacity: 0;
    transition: opacity .15s;
}
.toast.show { opacity: 1; }

/* Tyhjä tila */
.empty {
    padding: 64px 0;
    text-align: center;
    color: var(--muted);
    font-size: 15px;
}

/* Mobiili */
@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { padding: 24px; border-right: none; border-bottom: 1px solid var(--hair); }
    .main { padding: 24px 16px; }
    .ticket-grid { grid-template-columns: 1fr; }
    .list th, .list td { padding: 12px 8px; }
}

/* Wordmark */
.sidebar-brand {
    display: block;
    font-size: 22px;
    font-weight: 650;
    color: var(--ink);
    letter-spacing: -0.02em;
    margin-bottom: 40px;
    text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; color: var(--ink); }

.login-brand {
    font-size: 40px;
    font-weight: 650;
    color: var(--ink);
    letter-spacing: -0.03em;
    margin-bottom: 40px;
    line-height: 1;
}

/* Raportit KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 40px; margin-top: 40px; }
.kpi { }
.kpi-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; margin-bottom: 16px; }
.kpi-num { font-size: 48px; font-weight: 650; color: var(--oak); line-height: 1; letter-spacing: -0.02em; }
.kpi-meta { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* Logo image containers */
.sidebar-brand img { display: block; height: auto; }
.login-brand      { margin-bottom: 40px; }
.login-brand img  { display: block; height: auto; }

/* Chat-tyyppinen viestikanava (whatsapp / chat / instagram / messenger) */
.chat { display: flex; flex-direction: column; gap: 24px; padding: 8px 0; }
.chat-msg { max-width: 82%; padding: 12px 16px; background: var(--surface); border: 1px solid var(--hair); }
.chat-msg.self { align-self: flex-end; background: var(--bg-alt); }
.chat-msg .who { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.chat-msg .body { white-space: pre-wrap; line-height: 1.55; }

/* Ryhmittele saman lähettäjän peräkkäiset viestit — vähemmän tilaa väliin */
.chat-msg + .chat-msg { margin-top: -16px; }
.chat-msg.new-turn + .chat-msg { margin-top: 0; }

/* Vanhojen msg-luokkien styles pysyvät email/puhelu-näkymässä */

/* Kanavakytkennät */
.channels { display: flex; flex-direction: column; }
.channel { padding: 32px 0; border-top: 1px solid var(--hair); }
.channel:first-child { border-top: none; padding-top: 8px; }
.channel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 40px; }
.channel-head h2 { margin: 0; }
.channel-head .meta { margin-top: 4px; max-width: 520px; }
.channel-status { flex-shrink: 0; font-size: 15px; }
.channel-body { margin-top: 24px; max-width: 720px; }
.env-block {
    background: var(--bg-alt);
    padding: 16px 20px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 13px;
    color: var(--ink);
    border: 1px solid var(--hair);
    white-space: pre-wrap;
    word-break: break-all;
}

/* Flashit */
.flash-ok { background: #ecfdf5; border: 1px solid #a7f3d0; padding: 12px 16px; color: #065f46; margin-bottom: 24px; }
.flash-err { background: #fee2e2; border: 1px solid #fca5a5; padding: 12px 16px; color: #991b1b; margin-bottom: 24px; }

/* Chat-wrapperin ja composerin layout — WhatsApp-tyylinen sticky-reply */
.chat-wrap {
    display: flex; flex-direction: column;
    height: calc(100vh - 80px);
    margin: -40px -64px;
    padding: 0;
}
.chat-header {
    padding: 24px 64px 16px;
    border-bottom: 1px solid var(--hair);
    background: var(--surface);
    flex-shrink: 0;
}
.chat-header h1 { font-size: 22px; margin: 0; }
.chat-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 32px 64px;
    background: var(--bg);
    display: flex; flex-direction: column; gap: 20px;
}
.chat-composer {
    padding: 16px 64px 24px;
    border-top: 1px solid var(--hair);
    background: var(--surface);
    flex-shrink: 0;
}
.chat-composer textarea {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--font);
    font-size: 15px;
    border: 1px solid var(--hair);
    border-radius: 0;
    background: var(--surface);
    resize: vertical;
    min-height: 60px;
}
.chat-composer textarea:focus { border-color: var(--ink); outline: none; }
.chat-composer-actions {
    display: flex; gap: 12px; justify-content: flex-end; margin-top: 12px;
}
.chat-draft-hint {
    font-size: 13px; color: var(--oak); font-weight: 500; margin-bottom: 8px;
    display: flex; align-items: center; gap: 8px;
}
.chat-draft-hint::before { content: '●'; font-size: 10px; }

/* Chat-msg WhatsApp-tyylisenä (suorat kulmat!) */
.chat-msg { max-width: 70%; padding: 12px 16px; background: var(--surface); border: 1px solid var(--hair); }
.chat-msg.self { align-self: flex-end; background: #fff4e6; border-color: #e8d4b8; }
.chat-msg .who { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chat-msg .body { white-space: pre-wrap; line-height: 1.5; }
.chat-msg + .chat-msg { margin-top: -12px; }
.chat-msg.new-turn { margin-top: 8px; }

/* Msg (email/voice) samalla logiikalla */
.msg { max-width: 75%; padding: 14px 18px; background: var(--surface); border: 1px solid var(--hair); }
.msg.out { align-self: flex-end; background: var(--bg-alt); }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.msg .body { white-space: pre-wrap; line-height: 1.55; }

/* KPI bar */
.kpi-bar { margin-top: 12px; height: 3px; background: var(--bg-alt); overflow: hidden; }
.kpi-bar-fill { height: 100%; background: var(--ink); }

/* Report row */
.report-row { display: grid; grid-template-columns: 200px 1fr 60px; gap: 24px; align-items: center; padding: 12px 0; }
.report-row-label { font-size: 15px; }
.report-row-bar { height: 3px; background: var(--bg-alt); overflow: hidden; }
.report-row-fill { height: 100%; background: var(--ink); }
.report-row-num { font-size: 15px; font-weight: 500; text-align: right; }

/* Channel grid */
.channel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; }
.channel-card { background: var(--surface); border: 1px solid var(--hair); padding: 0; display: flex; flex-direction: column; }
.channel-card-body { padding: 24px; flex: 1; }
.channel-card-title { font-size: 17px; font-weight: 650; color: var(--ink); margin-bottom: 8px; }
.channel-card-desc { font-size: 13px; color: var(--muted); line-height: 1.55; }
.channel-card-foot { padding: 16px 24px; border-top: 1px solid var(--hair); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.channel-status-ok      { color: #065f46; font-size: 13px; font-weight: 500; }
.channel-status-partial { color: #92400e; font-size: 13px; font-weight: 500; }
.channel-status-off     { color: var(--muted); font-size: 13px; font-weight: 500; }
.channel-status-soon    { color: var(--muted); font-size: 13px; }
.channel-action         { font-size: 13px; }

/* Kilkilkki responsiivinen */
@media (max-width: 768px) {
    .chat-wrap { height: auto; margin: 0; }
    .chat-scroll { max-height: 60vh; padding: 20px; }
    .chat-header { padding: 20px; }
    .chat-composer { padding: 16px 20px; }
    .report-row { grid-template-columns: 1fr; gap: 4px; }
}

/* Automation policy cards */
.policy {
    padding: 32px 0;
    border-top: 1px solid var(--hair);
}
.policy:first-of-type { border-top: 0; padding-top: 0; }
.policy-head {
    display: flex; justify-content: space-between; align-items: baseline; gap: 24px;
    margin-bottom: 20px;
}
.policy-head h2 {
    font-size: 17px; font-weight: 650; margin: 0;
}
.policy-threshold {
    display: flex; align-items: center; gap: 12px;
}
.policy-threshold input {
    width: 76px; padding: 6px 10px;
    border: 1px solid var(--hair);
    background: var(--surface);
    font-family: var(--font); font-size: 14px;
    text-align: center;
}
.policy-cards {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}
.policy-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--hair);
    padding: 20px;
    cursor: pointer;
    transition: none;
    position: relative;
}
.policy-card input[type=radio] {
    position: absolute; opacity: 0; pointer-events: none;
}
.policy-card:hover { background: var(--bg-alt); }
.policy-card.is-active {
    border-color: var(--ink);
    background: var(--bg-alt);
    box-shadow: inset 4px 0 0 var(--oak);
}
.policy-card-title {
    font-size: 15px; font-weight: 650; color: var(--ink); margin-bottom: 6px;
}
.policy-card-body {
    font-size: 13px; color: var(--muted); line-height: 1.5;
}

@media (max-width: 768px) {
    .policy-cards { grid-template-columns: 1fr; }
    .policy-head { flex-direction: column; align-items: flex-start; gap: 12px; }
}

/* Number input jäljittelee muita fieldejä */
input[type=number] { border-radius: 0; }

/* Inbox — unread rivi (asiakas vastannut, agent ei) */
.list tr.row-unread td { font-weight: 650; }
.list tr:hover { background: var(--bg-alt); cursor: pointer; }
.state-awaiting_customer { color: var(--muted); }


/* --- Liitteet (tkt_attachments) --- */
.atts { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }
.att { display:inline-flex; align-items:center; gap:8px; padding:6px 10px; background:#f9fafb; border:1px solid #e5e7eb; border-radius:8px; text-decoration:none; color:#374151; font-size:13px; transition:background .12s; }
.att:hover { background:#f3f4f6; border-color:#d1d5db; color:#111827; }
.att-icon { font-size:16px; }
.att-name { font-weight:500; max-width:220px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.att-size { color:#9ca3af; font-size:12px; }
.att-img { padding:0; border-radius:8px; overflow:hidden; }
.att-img img { display:block; max-width:200px; max-height:200px; object-fit:cover; }

.body-html iframe { display:block; background:#fff; border-radius:6px; }

/* --- Composer: attachment picker --- */
.att-picker { margin-top:8px; display:flex; align-items:center; gap:12px; flex-wrap:wrap; }
.att-btn { display:inline-flex; align-items:center; gap:6px; padding:6px 12px; background:#f9fafb; border:1px solid #e5e7eb; border-radius:8px; font-size:13px; color:#374151; cursor:pointer; transition:background .12s; }
.att-btn:hover { background:#f3f4f6; }
.att-list { display:flex; flex-wrap:wrap; gap:6px; }
.att-chip { padding:4px 10px; background:#e0f2fe; color:#075985; border-radius:12px; font-size:12px; }
