/* ==========================================================
   RAKMENTOR – BRAND BOOK 2026  (sama pohja kuin kuntoarviossa)
========================================================== */
:root {
    --glacier: #C3D9E8;
    --glacier-lighter: #CFE1ED;
    --glacier-soft: #EAF2F8;
    --charcoal: #3B404C;
    --stone: #D0CFC4;
    --stone-lighter: #D9D9D0;
    --gray: #F5F5F5;
    --line: #E7E7E1;
    --line-soft: #ECECE6;
    --white: #FFFFFF;
    --text: #181818;
    --muted: #6B7080;
    --success: #148235;
    --error: #C94C0E;
    --link: #497798;
    --accent-warm: #E7D0B8;

    --radius: 14px;
    --radius-sm: 10px;
    --font: "Atkinson Hyperlegible", "Atkinson Hyperlegible Next", Arial, sans-serif;
    --mono: "Atkinson Hyperlegible Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    background: var(--gray);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: var(--font); color: inherit; }

h1, h2 { font-weight: 400; letter-spacing: -0.01em; color: var(--charcoal); }
h1 { font-size: 26px; margin: 0 0 6px; }
h2 { font-size: 22px; margin: 0 0 14px; }
h3 { font-size: 17px; font-weight: 700; margin: 22px 0 8px; color: var(--charcoal); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.loading { text-align: center; padding: 60px; color: var(--muted); }

/* ==========================================================
   YLÄPALKKI + TABIT
========================================================== */
.topbar {
    position: sticky; top: 0; z-index: 50;
    background: var(--white);
    border-bottom: 1px solid var(--stone-lighter);
}
.topbar-inner, .tabs { max-width: 1180px; margin: 0 auto; }
.topbar-inner {
    padding: 12px 20px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; text-decoration: none; color: inherit; }
.brand-logo { height: 24px; width: auto; }
.brand-app {
    font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--muted); padding-left: 14px; border-left: 1px solid var(--stone); white-space: nowrap;
}
.brand-kohde {
    font-size: 15px; color: var(--charcoal);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32vw;
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.save-status {
    font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em;
    padding: 5px 10px; border-radius: 999px;
    background: var(--gray); color: var(--muted); white-space: nowrap;
}
.save-status::before {
    content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    margin-right: 7px; vertical-align: 1px; background: var(--stone);
}
.save-status[data-state="saving"]::before, .save-status[data-state="dirty"]::before { background: var(--link); }
.save-status[data-state="saved"]::before { background: var(--success); }
.save-status[data-state="error"]::before { background: var(--error); }
.save-status:empty { display: none; }

.tabs { padding: 0 20px; display: flex; gap: 4px; overflow-x: auto; }
.tabs:empty { display: none; }
.tab {
    appearance: none; border: 0; background: transparent;
    padding: 12px 14px 13px;
    font-family: var(--mono); font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--muted); cursor: pointer; text-decoration: none;
    border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab-num { opacity: 0.6; margin-right: 4px; }
.tab:hover { color: var(--charcoal); }
.tab.active { color: var(--charcoal); border-bottom-color: var(--glacier); font-weight: 500; }

/* lakiperusteen valinta (segmentti) */
.seg { display: inline-flex; border: 1px solid var(--stone); border-radius: 999px; padding: 3px; background: var(--white); }
.seg-btn {
    border: 0; background: transparent; padding: 7px 13px; border-radius: 999px;
    font-family: var(--mono); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase;
    cursor: pointer; color: var(--muted); white-space: nowrap;
}
.seg-btn.on { background: var(--charcoal); color: var(--white); }

/* ==========================================================
   SISÄLTÖ
========================================================== */
.container { max-width: 1180px; margin: 0 auto; padding: 20px 20px 120px; }
.narrow { max-width: 860px; margin: 0 auto; }

.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-cta { background: var(--glacier-soft); border-color: var(--glacier); }

.label {
    display: block;
    font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 6px;
}
.badge, .tag {
    font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
    background: var(--gray); color: var(--muted);
    padding: 3px 8px; border-radius: 999px; vertical-align: 2px; margin-left: 8px;
}
.tag { background: var(--glacier-soft); color: var(--charcoal); }
.notice {
    background: var(--glacier-soft); border: 1px solid var(--glacier); color: var(--charcoal);
    border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 14px; font-size: 14.5px;
}
.badge-warn {
    background: #F6E2D6; color: var(--error); border-radius: 999px; padding: 4px 10px;
    font-family: var(--mono); font-size: 11px; letter-spacing: .04em;
}

/* ==========================================================
   LOMAKKEET
========================================================== */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.grid .wide { grid-column: 1 / -1; }
.field { display: block; }
.field > label {
    display: block;
    font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 6px;
}
.field + .field { margin-top: 14px; }
.grid .field + .field { margin-top: 0; }

input[type="text"], input[type="email"], input[type="tel"], input[type="date"], input[type="number"], input[type="search"],
input:not([type]), select, textarea, .plain {
    width: 100%;
    font-size: 16px; color: var(--text); background: var(--white);
    border: 1px solid var(--stone); border-radius: var(--radius-sm);
    padding: 11px 13px;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--charcoal); box-shadow: 0 0 0 3px var(--glacier-lighter);
}
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%233B404C' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}
.select-sm { width: auto !important; padding: 7px 32px 7px 11px !important; font-size: 14px !important; }

/* ==========================================================
   PAINIKKEET
========================================================== */
.btn {
    appearance: none; border: 1px solid var(--stone); border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-family: var(--mono); font-size: 12.5px; letter-spacing: 0.06em; text-transform: uppercase;
    cursor: pointer; color: var(--charcoal); background: var(--white);
    transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:hover { border-color: var(--charcoal); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--glacier); border-color: var(--glacier); }
.btn.primary:hover { background: #B3CEE0; border-color: #B3CEE0; }
.btn.dark { background: var(--charcoal); border-color: var(--charcoal); color: var(--white); }
.btn.small { padding: 7px 12px; font-size: 11.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--gray); border-color: transparent; }
.btn.phrase { background: var(--glacier-soft); border-color: var(--glacier); }
.btn.danger { color: var(--error); border-color: #EBC9B8; }
.btn.danger:hover { border-color: var(--error); }

.iconbtn {
    width: 30px; height: 30px; flex: none;
    border: 1px solid var(--stone); background: var(--white); border-radius: 8px;
    cursor: pointer; color: var(--muted); font-size: 13px; line-height: 1;
}
.iconbtn:hover { border-color: var(--charcoal); color: var(--charcoal); }
.iconbtn.danger:hover { border-color: var(--error); color: var(--error); }
.iconbtn:disabled { opacity: .35; cursor: default; }

/* ==========================================================
   ALOITUS / RAPORTTILISTA
========================================================== */
.laki-big { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 14px; }
.laki-big button {
    text-align: left; border: 1.5px solid var(--stone); background: var(--white);
    border-radius: var(--radius); padding: 14px; cursor: pointer;
    display: flex; flex-direction: column; gap: 6px;
}
.laki-big button:hover { border-color: var(--charcoal); }
.laki-big button.on { border-color: var(--charcoal); background: var(--glacier-soft); box-shadow: 0 0 0 3px var(--glacier-lighter); }
.laki-big strong { font-size: 16px; color: var(--charcoal); }
.laki-big span { font-size: 13px; color: var(--muted); }

.projects { display: grid; gap: 6px; }
.proj {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 11px 14px; border: 1px solid var(--line); background: var(--gray);
    border-radius: var(--radius-sm); cursor: pointer;
}
.proj:hover { background: var(--glacier-soft); border-color: var(--glacier); }
.proj .meta { font-family: var(--mono); font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.proj-actions { display: flex; gap: 6px; }

/* ==========================================================
   HAVAINNOT: SIVUPALKKI + OSIOT
========================================================== */
.osio-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 18px; align-items: start; }
.osio-side {
    position: sticky; top: 112px;
    background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 10px; max-height: calc(100vh - 130px); overflow-y: auto;
}
.side-group {
    font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
    color: var(--muted); padding: 10px 10px 4px;
}
.side-item {
    width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 9px 10px; border: 0; background: none; border-radius: 9px;
    cursor: pointer; text-align: left; font-size: 14.5px; color: var(--text); text-decoration: none;
}
.side-item:hover { background: var(--gray); }
.side-item.active { background: var(--glacier-soft); box-shadow: inset 3px 0 0 var(--charcoal); }
.side-num { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-right: 6px; }
.count {
    font-family: var(--mono); font-size: 10.5px;
    background: var(--charcoal); color: #fff; border-radius: 999px; padding: 1px 7px;
}
.side-select { display: none; }

.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head .side-num { font-size: 14px; }
.section-head .otsikko-input { flex: 1; font-size: 20px; font-weight: 400; color: var(--charcoal); padding: 8px 12px; }
.empty-note { background: var(--gray); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--muted); font-size: 14px; margin: 10px 0; }

/* havaintokortti */
.finding {
    border: 1px solid var(--line); border-radius: var(--radius);
    background: #FCFCFB; margin: 14px 0; overflow: visible;
}
.finding-head {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; border-bottom: 1px solid var(--line-soft);
    background: var(--white); border-radius: var(--radius) var(--radius) 0 0;
}
.finding-head .tid {
    font-family: var(--mono); font-size: 13px; font-weight: 500;
    background: var(--charcoal); color: #fff; border-radius: 8px;
    padding: 6px 9px; min-width: 42px; text-align: center;
}
.finding-head select { width: auto; padding: 8px 32px 8px 10px; font-size: 13px; }
.finding-head .otsikko { flex: 1; font-weight: 700; }
.finding-body {
    padding: 14px; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px 14px; align-items: start;
}
.finding-body > .label { padding-top: 13px; margin: 0; }
.finding-body textarea { min-height: 54px; }
.finding-foot { grid-column: 1 / -1; display: flex; justify-content: flex-end; }

.peruste-wrap { position: relative; }
span.peruste-wrap { display: inline-block; }
.peruste-tools { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }

.phrase-menu {
    position: absolute; z-index: 40; left: 0; top: 100%; margin-top: 6px;
    width: min(640px, calc(100vw - 40px));
    background: var(--white); border: 1px solid var(--stone); border-radius: var(--radius-sm);
    box-shadow: 0 12px 32px rgba(0,0,0,.14); max-height: 360px; overflow: auto;
}
.phrase-menu .ph-title {
    font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
    color: var(--muted); padding: 10px 14px 6px;
}
.phrase-menu button {
    display: block; width: 100%; text-align: left; border: 0; background: none;
    padding: 9px 14px; cursor: pointer; font-size: 14.5px; line-height: 1.4; border-top: 1px solid var(--line-soft);
}
.phrase-menu button:hover { background: var(--glacier-soft); }

/* kuvat */
.photos { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.photo { display: flex; flex-direction: column; gap: 6px; }
.photo-img { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--gray); border: 1px solid var(--line); }
.photo-img img { width: 100%; aspect-ratio: 4/3; object-fit: contain; display: block; background: #FAFAF8; }
.photo-delete {
    position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%;
    border: 0; background: rgba(59, 64, 76, .85); color: var(--white); cursor: pointer; font-size: 13px;
}
.photo-move { position: absolute; left: 8px; top: 8px; display: flex; gap: 4px; }
.photo-move button {
    width: 28px; height: 28px; border-radius: 50%; border: 0; cursor: pointer;
    background: rgba(255,255,255,.9); color: var(--charcoal); font-size: 13px;
}
.photo-move button:disabled { opacity: .35; }
.pnum { font-family: var(--mono); font-size: 11.5px; letter-spacing: .04em; color: var(--muted); }
.photo textarea { min-height: 44px; font-size: 15px; padding: 9px 12px; resize: vertical; }

.dropzone {
    display: flex; align-items: center; justify-content: center; flex-direction: column;
    min-height: 158px; border: 1.5px dashed var(--stone); border-radius: var(--radius);
    background: var(--gray); cursor: pointer; text-align: center;
    color: var(--muted); font-size: 14px; padding: 16px;
}
.dropzone::before {
    content: ""; display: block; width: 32px; height: 32px; margin: 0 auto 8px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7080' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 8h3l2-3h6l2 3h3v11H4z'/%3E%3Ccircle cx='12' cy='13' r='3.5'/%3E%3C/svg%3E") center/contain no-repeat;
}
.dropzone:hover, .dropzone.over { border-color: var(--charcoal); background: var(--glacier-soft); }
.uploading { opacity: .55; }

.cover-prev { width: 100%; max-width: 380px; aspect-ratio: 510/383; object-fit: cover; border-radius: var(--radius); display: block; background: var(--gray); }
.sig-prev { max-height: 60px; display: block; margin-bottom: 8px; }

/* listat */
.listedit .row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.listedit .row textarea { flex: 1; min-height: 44px; padding: 9px 12px; font-size: 15px; }
.listedit .bullet { padding-top: 10px; color: var(--muted); }

/* liiterivit */
.liite { margin-top: 18px; border-top: 1px solid var(--line-soft); padding-top: 6px; }
.table-wrap { overflow-x: auto; margin: 10px 0; }
table.rows, table.summary { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rows th, table.summary th {
    background: var(--charcoal); color: #fff;
    font-family: var(--mono); font-weight: 400; font-size: 12px; letter-spacing: .04em;
    padding: 8px; text-align: left; white-space: nowrap;
}
table.rows td { padding: 4px 4px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.rows td.tid { font-family: var(--mono); font-weight: 500; padding: 12px 8px; width: 48px; }
table.rows textarea {
    border: 1px solid transparent !important; background: transparent !important;
    padding: 7px 8px !important; font-size: 14px !important; min-height: 40px; border-radius: 6px !important;
}
table.rows textarea:hover { border-color: var(--stone) !important; background: #fff !important; }
table.rows textarea:focus { border-color: var(--charcoal) !important; background: #fff !important; box-shadow: none; }
table.rows td.acts { white-space: nowrap; width: 72px; padding-top: 8px; }
table.summary td { padding: 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.summary td:first-child { font-family: var(--mono); font-weight: 500; white-space: nowrap; }
table.summary tr:nth-child(even) td { background: #FAFAF8; }
table.summary td.missing { color: var(--error); font-style: italic; }

/* mallilauseet */
.phr-cat { margin-bottom: 26px; }
.phr-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-start; }
.phr-row textarea { flex: 1; min-height: 44px; padding: 9px 12px; font-size: 15px; }

/* ==========================================================
   TOAST + OVERLAY
========================================================== */
.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
    background: var(--charcoal); color: var(--white);
    padding: 12px 18px; border-radius: var(--radius-sm); font-size: 15px;
    z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: calc(100% - 32px);
}
.toast.error { background: var(--error); }
.overlay {
    position: fixed; inset: 0; background: rgba(245,245,245,.92); z-index: 300;
    display: flex; align-items: center; justify-content: center;
}
.overlay-box { text-align: center; color: var(--charcoal); }
.spinner {
    width: 44px; height: 44px; margin: 0 auto 18px;
    border: 4px solid var(--glacier); border-top-color: var(--charcoal); border-radius: 50%;
    animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================
   MOBIILI
========================================================== */
@media (max-width: 900px) {
    .osio-layout { grid-template-columns: minmax(0, 1fr); }
    .osio-side { position: sticky; top: 104px; z-index: 30; padding: 8px; max-height: none; overflow: visible; }
    .side-list, .osio-side .side-group, .osio-side .hint { display: none; }
    .side-select { display: block; font-weight: 700; }
}
@media (max-width: 720px) {
    .container { padding: 14px 12px 110px; }
    .card { padding: 16px; border-radius: 12px; }
    .topbar-inner { padding: 10px 14px; flex-wrap: wrap; }
    .brand-app, .brand-kohde { display: none; }
    .tabs { padding: 0 8px; }
    .tab { padding: 11px 10px 12px; font-size: 12px; }
    .grid { grid-template-columns: minmax(0, 1fr); }
    .laki-big { grid-template-columns: 1fr; }
    .finding-head { flex-wrap: wrap; }
    .finding-head select { flex: 1; min-width: 0; }
    .finding-head .otsikko { flex-basis: 100%; order: 5; }
    .section-head .otsikko-input { flex-basis: calc(100% - 40px); font-size: 18px; }
    .section-head .select-sm { width: 100% !important; }
    .topbar-right .btn.small { padding: 7px 9px; }
    .finding-body { grid-template-columns: minmax(0, 1fr); }
    .finding-body > .label { padding-top: 0; }
    .save-status { font-size: 0; padding: 6px; }
    .save-status::before { margin-right: 0; }
    .proj { flex-wrap: wrap; }
    table.rows, table.rows tbody, table.rows tr, table.rows td { display: block; width: 100%; }
    table.rows tr:first-child { display: none; }
    table.rows tr { border-bottom: 2px solid var(--line); padding: 6px 0; }
    table.rows td { border: 0; }
}
