/* Saarefoto CRM — tume stuudio */
:root {
  --bg: #17191e;
  --card: #1e2127;
  --card2: #22252c;
  --text: #e6e9ef;
  --muted: #8b93a1;
  --line: #2c313a;
  --line2: #333947;
  --accent: #5b8def;
  --accent-dark: #6f9cf2;
  --accent-text: #0e1526;
  --danger: #e07b6d;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5;
}
a { color: #7ea6f4; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 28px; margin: 0 0 20px; }
h1 .h1sub { font-size: 16px; font-weight: normal; }
h2 { font-size: 18px; margin: 0 0 14px; display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); }
.center { text-align: center; display: block; }

/* Paigutus */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: #111318; color: #c6cdd8; padding: 18px 0;
  display: flex; flex-direction: column; gap: 10px; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 4px 18px 12px; font-weight: 700; font-size: 18px; }
.brand a { color: #fff; }
.sidesearch { padding: 0 12px; position: relative; }
.sidesearch input {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid #262b34;
  background: #1a1e25; color: #e6e9ef; font-size: 14px;
}
.sidesearch input::placeholder { color: #6b7382; }
.sidesearch-results {
  position: absolute; left: 12px; right: 12px; top: calc(100% + 4px); z-index: 70;
  background: #22252c; border: 1px solid var(--line2); border-radius: 8px;
  max-height: 70vh; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,.55); padding: 4px;
}
.sidesearch-results[hidden] { display: none; }
.ss-item {
  display: flex; gap: 7px; align-items: baseline; padding: 7px 9px; border-radius: 6px;
  color: #dfe4ec; font-size: 13px; text-decoration: none !important; white-space: nowrap;
  overflow: hidden;
}
.ss-item span { overflow: hidden; text-overflow: ellipsis; }
.ss-item em { color: #8b93a1; font-style: normal; font-size: 12px; }
.ss-item:hover { background: #2b3340; }
.ss-empty { padding: 10px; color: #8b93a1; font-size: 13px; }
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a {
  padding: 11px 18px; color: #aeb6c3; display: flex; gap: 11px; align-items: center;
}
.sidebar nav a:hover { background: #1a1e25; text-decoration: none; }
.sidebar nav a.active { background: #232a35; color: #fff; font-weight: 600; }
.sidebar .ic { width: 20px; text-align: center; }
.sideuser { margin-top: auto; padding: 10px 16px; font-size: 13px; color: #7d8694;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sideuser .linkbtn { color: #7d8694; }
.mobilebar { display: none; }
.content { flex: 1; min-width: 0; width: 100%; padding: 30px 36px 70px; max-width: 1800px; }

/* Kaardid */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 22px;
}
.card.warn { background: #26201a; border-color: #4a3a24; }
.twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.twocol .card { margin-bottom: 0; }

/* Päis */
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.pagehead h1 { margin-bottom: 12px; }

/* Vormid */
input[type=text], input[type=search], input[type=email], input[type=password],
input[type=date], input[type=time], input[type=number], select, textarea {
  padding: 10px 12px; border: 1px solid var(--line2); border-radius: 8px;
  font: inherit; background: #15181d; color: var(--text); max-width: 100%;
  color-scheme: dark;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #2f4c86; border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: #6b7382; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 600; margin-bottom: 10px; }
label input, label select, label textarea { font-weight: normal; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.right { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 150px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
/* Lahtrid venivad võrdse kõrguseni; sisendkast lükatakse lahtri põhja, et
   kõrvutised read oleks ühel joonel ka siis, kui üks silt on kahel real. */
.grid2 > label > input, .grid2 > label > select, .grid2 > label > textarea { margin-top: auto; }
.editform { max-width: 950px; }
.chk { flex-direction: row; align-items: center; gap: 6px; font-weight: normal; display: flex; }
.chkgroup { display: flex; flex-direction: column; gap: 2px; font-weight: normal; }
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { min-width: 320px; }

/* Töölaua loendurid */
.counters { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.counter {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--line); text-decoration: none !important; cursor: pointer;
}
.counter:hover { border-color: var(--line2); background: var(--card2); }
.counter .c-lbl { font-size: 13px; color: var(--muted); }
.counter .c-num { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1.1; }
.counter.c-danger { background: #2a1c1a; border-color: #4d322e; }
.counter.c-danger .c-lbl, .counter.c-danger .c-num { color: #ef9287; }
.counter.c-danger.empty { background: var(--card); border-color: var(--line); }
.counter.c-danger.empty .c-lbl { color: var(--muted); } .counter.c-danger.empty .c-num { color: var(--text); }
.counter.c-accent { background: #1a2436; border-color: #2f4c86; }
.counter.c-accent .c-lbl, .counter.c-accent .c-num { color: #8ab4f0; }
.counter.c-warning { background: #2a2410; border-color: #4a3a24; }
.counter.c-warning .c-lbl, .counter.c-warning .c-num { color: #ddc25e; }

/* Kokkutõmmatavad sektsioonikaardid */
details.seccard { padding: 0; }
details.seccard > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; font-size: 16px; font-weight: 600;
}
details.seccard > summary::-webkit-details-marker { display: none; }
details.seccard > summary::before { content: '▸'; color: var(--muted); font-size: 12px; transition: transform .12s; }
details.seccard[open] > summary::before { transform: rotate(90deg); }
details.seccard > summary .sec-n {
  margin-left: auto; background: var(--card2); color: var(--muted); font-size: 13px;
  padding: 1px 10px; border-radius: 20px; font-weight: 700;
}
details.seccard.warn > summary .sec-n { background: #3d2523; color: #e89a8c; }
details.seccard > .tasklist, details.seccard > .plainlist, details.seccard > p { margin: 0 18px 16px; }
details.seccard > .plainlist { padding-top: 2px; }
.counter.flash-target, details.seccard.flash-target > summary { animation: pulsehl 1s ease; }
@keyframes pulsehl { 0% { box-shadow: 0 0 0 2px var(--accent); } 100% { box-shadow: none; } }

/* Otse muudetav kaardivorm */
.savebar { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.savebar .unsaved { font-size: 13px; color: #e8c06a; }
form.livesave.dirty .btn.primary { box-shadow: 0 0 0 2px #2f4c86; }

/* Hulgivalik tabelis */
.checkcol { width: 34px; text-align: center; }
.checkcol input { width: 16px; height: 16px; cursor: pointer; }
.bulkbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 60;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: 94vw;
  background: #1c2534; border: 1px solid var(--accent); border-radius: 12px;
  padding: 10px 16px; box-shadow: 0 10px 32px rgba(0,0,0,.55);
}
.bulkbar[hidden] { display: none; }
/* Reasisese valiku salvestamise vilkuv kinnitus */
select.inlinesel.saved-blink { outline: 2px solid #7fd6a4; border-color: #7fd6a4; }
.bulktable tbody tr { cursor: pointer; }
.bulktable tbody tr.selrow td { background: #1c2534 !important; }

/* Reasisene kiirmuutmine (staatus/etapp otse tabelist) */
select.inlinesel {
  padding: 3px 6px; font-size: 12.5px; border-radius: 7px;
  background: #191d24; border-color: var(--line);
}
select.inlinesel:hover { border-color: var(--line2); }

/* Nupud */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line2);
  background: #262b34; color: #e2e6ee; cursor: pointer; font: inherit; font-weight: 600;
  text-decoration: none !important; white-space: nowrap;
}
.btn:hover { background: #2e3440; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #4d322e; }
.btn.danger:hover { background: #2c2220; }
.btn.small { padding: 6px 11px; font-size: 14px; }
.btn.wide { width: 100%; }
.linkbtn { background: none; border: none; color: #7ea6f4; cursor: pointer; font: inherit; padding: 2px 4px; }
.inline { display: inline; }

/* Tabelid */
table.list { width: 100%; border-collapse: collapse; font-size: 15px; }
table.list th {
  text-align: left; font-size: 13px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 8px 12px; border-bottom: 2px solid var(--line2);
}
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:hover td { background: #22262d; }

/* Sildid */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 13px;
  font-weight: 600; background: #2a2d33; color: #aeb6c0; white-space: nowrap;
}
.b-uus-lead { background: #1e3a2a; color: #7fd6a4; }
.b-suhtlemisel { background: #3a3320; color: #e8c06a; }
.b-proovida-uuesti { background: #2d2a45; color: #b3a7f2; }
.b-pole-huvitatud { background: #2a2d33; color: #9aa3ae; }
.b-kaotatud { background: #3d2523; color: #e89a8c; }
.b-esmane-kontakt { background: #1f2d45; color: #8ab4f0; }
.b-info-saadetud { background: #2d2a45; color: #b3a7f2; }
.b-follow-up { background: #3a2d1e; color: #dfa96e; }
.b-otsust-ootamas { background: #38331b; color: #ddc25e; }
.b-kinnitatud { background: #1e3a2a; color: #7fd6a4; }
.b-tehtud { background: #173430; color: #6cc9b4; }
.b-on-hold { background: #2a2d33; color: #a7b0bc; }
.b-kone { background: #3a3320; color: #e8c06a; }
.b-e-mail { background: #1f2d45; color: #8ab4f0; }
.b-jarelmeil { background: #16333c; color: #72c3dd; }
.b-kohtumine { background: #2d2a45; color: #b3a7f2; }
.b-marge { background: #2a2d33; color: #aeb6c0; }
.b-follow-up-kone { background: #3a2d1e; color: #dfa96e; }
.b-kool { background: #1f2d45; color: #8ab4f0; }
.b-lasteaed { background: #3a2d1e; color: #e0a877; }
.b-kool-lasteaed { background: #2d2a45; color: #b3a7f2; }
.b-sygis { background: #3a2d1e; color: #dfa96e; }
.b-kevad { background: #1e3a2a; color: #7fd6a4; }
.b-direktor { background: #1f2d45; color: #8ab4f0; }
.b-huvijuht-oppejuht { background: #2d2a45; color: #b3a7f2; }
.b-arhiiv { background: #2a2d33; color: #9aa3ae; }
.b-toode { background: #2c3220; color: #b4ce74; }
.b-kingituseks { background: #1e3a2a; color: #7fd6a4; }
.b-arvega { background: #1f2d45; color: #8ab4f0; }
.b-pole-tehtud { background: #3d2523; color: #e89a8c; }
.b-pildipaev { background: #16333c; color: #72c3dd; }
.b-sunnipaev { background: #40233a; color: #f1a9d7; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.flash[hidden] { display: none; }
.flash-ok { background: #1e3a2a; color: #7fd6a4; }
.flash-err { background: #3d2523; color: #e89a8c; }
.flash-undo { background: rgba(255,255,255,.12); border: none; color: inherit; cursor: pointer;
  font: inherit; font-weight: 700; padding: 4px 12px; border-radius: 7px; white-space: nowrap; }
.flash-undo:hover { background: rgba(255,255,255,.22); }
.opt-new { color: #7ea6f4; font-weight: 700; }
.link-existing { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

/* Infokaart */
.infogrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; }
.infogrid .lbl { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 2px; }
.infogrid .wide { grid-column: 1 / -1; }

/* Ajajoon */
.logi-add { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 14px; }
.logi-add textarea { margin: 8px 0; }
.logi-contact-select { min-width: 210px; }
.logi-upload-row { align-items: center; }
.logi-upload-row .btn { margin-left: auto; }
.filepick {
  position: relative; display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 600;
}
.filepick:hover { color: var(--text); background: var(--card2); border-color: var(--line2); }
.filepick input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.logi-file-selection { font-size: 12px; }
.timeline { display: flex; flex-direction: column; }
.tl-group { display: flex; align-items: center; gap: 10px; margin: 16px 0 3px; color: #cbd2dc; font-size: 12px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; }
.tl-group::after { content: ""; height: 1px; background: var(--line2); flex: 1; }
.timeline > .tl-group:first-child { margin-top: 5px; }
.tl-item { padding: 10px 0 10px 14px; border-left: 3px solid var(--line2); margin-left: 4px; position: relative; }
.tl-item:target { scroll-margin-top: 18px; animation: logi-highlight 1.8s ease-out; }
@keyframes logi-highlight {
  0% { background: rgba(74, 125, 214, .22); box-shadow: 0 0 0 5px rgba(74, 125, 214, .12); }
  100% { background: transparent; box-shadow: none; }
}
.tl-item::before {
  content: ''; position: absolute; left: -7px; top: 16px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--card);
}
.tl-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tl-date-row { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; }
.tl-date { color: #d5dae2; font-weight: 750; }
.tl-edit-trigger { border: 0; padding: 0; background: none; font-family: inherit; cursor: pointer; }
.tl-edit-trigger:hover { color: #fff; text-decoration: underline; }
.tl-type-trigger { border: 0; font-family: inherit; cursor: pointer; }
.tl-type-trigger:hover { filter: brightness(1.2); box-shadow: 0 0 0 1px currentColor; }
.tl-age { color: var(--muted); }
.tl-newest { padding: 2px 7px; border-radius: 999px; background: #1f3554; color: #9fc7ff; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .3px; }
.tl-meta { color: var(--muted); font-size: 13px; }
.tl-links { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tl-title { display: block; margin-top: 8px; }
.logi-edit-form { margin: 10px 0 5px; padding: 12px; border: 1px solid var(--line2); border-radius: 9px; background: var(--card2); }
.logi-edit-form[hidden] { display: none; }
.logi-edit-form textarea { margin: 8px 0; }
.tl-del { margin-left: auto; }
.tl-del .linkbtn { color: #5b6270; }
.tl-del .linkbtn:hover { color: var(--danger); }
.tl-body { margin-top: 6px; color: #c3cad6; white-space: normal; }
.tl-full { margin-top: 8px; padding: 10px; background: #171a20; border-radius: 8px; }
details.tl-body summary { cursor: pointer; color: #c3cad6; }
details.tl-body summary em { color: #7ea6f4; font-style: normal; font-size: 13px; }
.tl-files { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-top: 8px; }
.tl-file {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--card2); font-size: 13px;
}
.tl-file .linkbtn { color: var(--muted); }
.tl-file .linkbtn:hover { color: var(--danger); }

/* Tegevused */
.task-add { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.tasklist { display: flex; flex-direction: column; gap: 10px; }
.task {
  display: grid; grid-template-columns: 145px 90px minmax(0, 1fr) auto; gap: 10px; padding: 11px 13px;
  background: var(--card2); border: 1px solid var(--line); border-radius: 9px;
  align-items: center;
}
.task.done { opacity: .72; }
.task.done .task-text { text-decoration: line-through; color: #6b7382; }
.task.overdue { border-left: 3px solid #b8664f; }
.task.overdue .task-date { color: #ef9287; font-weight: 700; }
.task-main { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; flex: 1; min-width: 0; }
.task-date { font-size: 13px; color: #9aa3b0; white-space: nowrap; }
.task-status-cell { display: flex; align-items: center; }
.task-status { display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 999px; white-space: nowrap; font-size: 12px; font-weight: 750; }
.task-status.status-open { background: #3a3320; color: #e8c06a; }
.task-status.status-done { background: #1e3a2a; color: #7fd6a4; }
.task-status-action { border: 0; font-family: inherit; cursor: pointer; }
.task-status-action:hover { filter: brightness(1.2); box-shadow: 0 0 0 1px currentColor; }
.task-text { border: 0; padding: 0; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.task-text:hover { color: #fff; text-decoration: underline; }
.task-links { flex: 0 0 100%; width: 100%; font-size: 13px; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.task-actions { display: flex; gap: 6px; align-items: center; }
.task-edit-pill { border: 0; font-family: inherit; cursor: pointer; }
.task-edit-pill:hover { filter: brightness(1.2); box-shadow: 0 0 0 1px currentColor; }
@media (max-width: 900px) {
  .task { grid-template-columns: 1fr; align-items: start; }
  .task-actions { justify-content: flex-start; }
}
.relation-pill {
  display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px;
  border: 1px solid #353b46; background: #252931; color: #aeb6c3;
  font-size: 12px; text-decoration: none !important; white-space: nowrap;
}
.relation-pill b { color: #d5dae2; margin-right: 4px; }
.pill-icon { margin-right: 4px; }
.relation-pill:hover { background: #303641; color: #fff; border-color: #596273; }
.user-pill.user-1 { background: #1f3554; border-color: #365b8b; color: #9fc7ff; }
.user-pill.user-2 { background: #392951; border-color: #62458b; color: #d0afff; }
.user-pill.user-3 { background: #203d31; border-color: #386b55; color: #96ddb9; }
.user-pill.user-4 { background: #493221; border-color: #7b5638; color: #f0bd8a; }
.user-pill.user-0 { background: #30333a; border-color: #4c515c; color: #b7bec9; }
.user-pill b { color: inherit; }
.doneflow { position: relative; }
.doneflow summary { list-style: none; cursor: pointer; }
.doneflow summary::-webkit-details-marker { display: none; }
.doneform {
  position: absolute; right: 0; z-index: 30; background: var(--card2); border: 1px solid var(--line2);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.5); padding: 14px; width: 420px; max-width: 90vw;
}
.doneform textarea { width: 100%; }

/* Rippmenüü-paneelid */
.dropdown { position: relative; }
.dropdown summary { list-style: none; cursor: pointer; display: inline-block; }
.dropdown summary::-webkit-details-marker { display: none; }
.droppanel {
  position: absolute; right: 0; z-index: 30; background: var(--card2); border: 1px solid var(--line2);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.5); padding: 14px; width: 360px; max-width: 90vw;
}

/* Nimekirjad */
.plainlist { list-style: none; margin: 0; padding: 0; }
.plainlist li { padding: 6px 0; border-bottom: 1px solid #242830; }
.plainlist li:last-child { border-bottom: none; }

/* Kalender */
.calcard { padding: 16px; }
.calgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.calhead { text-align: center; font-size: 14px; font-weight: 700; color: var(--muted); padding: 6px 0; }
.calday { position: relative; background: #1b1e24; border: 1px solid #262a32; border-radius: 8px; height: 140px; min-height: 140px; padding: 7px; font-size: 14px; overflow: hidden; }
.calday.empty { background: transparent; border: none; }
.calday.weekend { background: #191c22; }
.calday.today { border: 2px solid var(--accent); background: #1c2534; }
.calday[data-day] { cursor: pointer; }
.calday[data-day]:hover { border-color: var(--accent); background: #1e2530; }
.calday .addhint {
  position: absolute; top: 3px; right: 5px; color: var(--accent); font-size: 14px;
  font-weight: 700; opacity: 0; transition: opacity .1s;
}
.calday[data-day]:hover .addhint { opacity: 1; }
.caldate { font-weight: 700; font-size: 15px; margin-bottom: 5px; color: #aeb6c3; }
.calev {
  display: block; padding: 3px 7px; margin-bottom: 3px; border-radius: 6px; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none !important;
}
.calev.has-meta { white-space: normal; }
.calev.has-meta > span, .calev.has-meta small {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.calev.has-meta small { margin-top: 1px; opacity: .78; font-size: 11px; }
.calendar-event-edit { width: 100%; border: 0; text-align: left; font: inherit; cursor: pointer; }
.ev-foto { background: #173c34; color: #76d8bb; }
.ev-tahtaeg { background: #38331b; color: #ddc25e; }
.ev-syndmus { background: #2d2a45; color: #b3a7f2; }
.ev-puudumine { background: #4a2426; color: #ffaaa4; }
.ev-koolivaheaeg { background: #30343b; color: #d2d7df; }
.ev-tegevus { background: #22301d; color: #9ecb84; }
.ev-sunnipaev { background: #40233a; color: #f1a9d7; }
.ev-tegevus.done { opacity: .5; text-decoration: line-through; }
.callegend { display: flex; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.callegend .calev { display: inline-block; }
.calendar-filters {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); flex-wrap: wrap;
}
.calendar-filters .callegend { margin-top: 0; gap: 7px; }
.calfilter {
  display: inline-flex; align-items: center; padding: 5px 10px; border: 1px solid transparent;
  border-radius: 999px; color: var(--muted); background: #252931; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 700; opacity: .72;
}
.calfilter:hover { opacity: 1; }
.calfilter.active { opacity: 1; border-color: currentColor; box-shadow: 0 0 0 1px currentColor; }
.calfilter.filter-all { color: #d5dae2; }
.calfilter.filter-neutral { color: #b9c0cb; }
.cal-author-filter, .cal-event-filter { min-width: 210px; margin: 0; }
.cal-author-filter select, .cal-event-filter select { width: 100%; padding: 6px 9px; font-size: 13px; }
.calev[hidden], .agenda-item[hidden], #agenda-filter-empty[hidden] { display: none !important; }
.agenda-list { display: flex; flex-direction: column; }
#koik-kirjed { min-height: calc(100vh - 32px); scroll-margin-top: 16px; }
.agenda-section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.agenda-section-head h2 { margin-bottom: 0; }
.agenda-month-nav { flex-wrap: nowrap; }
.agenda-list .agenda-item {
  display: grid; grid-template-columns: 155px 90px minmax(0, 1fr) auto; gap: 16px;
  grid-template-areas: "date status main actions";
  align-items: start; padding: 13px 4px; border-bottom: 1px solid var(--line);
}
.agenda-date { grid-area: date; color: #c9d0da; font-weight: 700; white-space: nowrap; }
.agenda-status-cell { grid-area: status; display: flex; align-items: center; }
.agenda-main { grid-area: main; min-width: 0; }
.agenda-heading { display: flex; align-items: flex-start; gap: 9px; min-width: 0; }
.agenda-title { color: var(--text); font-weight: 650; min-width: 0; }
.agenda-title:hover { color: #fff; }
.agenda-edit-btn { padding: 0; border: 0; background: none; text-align: left; font: inherit; cursor: pointer; }
.agenda-text-details { min-width: 0; flex: 1; }
.agenda-text-details summary { color: var(--text); font-weight: 400; cursor: pointer; line-height: 1.45; }
.agenda-text-details summary em { color: #7ea6f4; font-size: 12px; font-style: normal; font-weight: 500; white-space: nowrap; }
.agenda-text-full { margin-top: 7px; padding: 8px 10px; border-radius: 7px; background: #171a20; color: #cbd2dc; font-weight: 400; }
.agenda-kind, .agenda-status, .agenda-pill {
  display: inline-flex; align-items: center; border-radius: 999px; white-space: nowrap;
}
.agenda-kind { padding: 3px 9px; background: #292d35; color: #c9d0da; font-size: 12px; font-weight: 700; line-height: 1.35; }
.agenda-kind.kind-tegevus { background: #283225; color: #b5d39f; }
.agenda-kind.kind-sunnipaev { background: #40233a; color: #f1a9d7; }
.agenda-kind.kind-pildistamine { background: #173c34; color: #76d8bb; }
a.agenda-kind { text-decoration: none; cursor: pointer; }
.agenda-kind-action { border: 0; font-family: inherit; cursor: pointer; }
a.agenda-kind:hover, .agenda-kind-action:hover { filter: brightness(1.2); box-shadow: 0 0 0 1px currentColor; }
.agenda-kind.kind-tahtaeg { background: #38331b; color: #ddc25e; }
.agenda-kind.kind-syndmus.variant-puudumine-puhkus { background: #4a2426; color: #ffaaa4; }
.agenda-kind.kind-syndmus.variant-koolivaheaeg { background: #30343b; color: #d2d7df; }
.agenda-kind.kind-syndmus.variant-muu-sundmus { background: #2d2a45; color: #b3a7f2; }
.agenda-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.agenda-pill { padding: 3px 8px; background: #252931; color: #aeb6c3; font-size: 12px; }
.agenda-pill b { color: #d5dae2; margin-right: 4px; }
a.agenda-pill { text-decoration: none; border: 1px solid #353b46; }
a.agenda-pill:hover { background: #303641; color: #fff; border-color: #596273; }
.agenda-actions { grid-area: actions; display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; }
.agenda-status { padding: 4px 9px; font-size: 12px; font-weight: 750; }
.agenda-status.status-open { background: #3a3320; color: #e8c06a; }
.agenda-status.status-done { background: #1e3a2a; color: #7fd6a4; }
.agenda-status-action { border: 0; font-family: inherit; cursor: pointer; }
.agenda-status-action:hover { filter: brightness(1.2); box-shadow: 0 0 0 1px currentColor; }
.agenda-item.is-done .agenda-title { color: var(--muted); text-decoration: line-through; }
.agenda-item.is-past:not(.is-task) { opacity: .7; }
.agenda-item.is-task.is-past:not(.is-done) .agenda-date { color: #e89a8c; }
@media (max-width: 900px) {
  .agenda-list .agenda-item {
    grid-template-columns: 130px 86px minmax(0, 1fr);
    grid-template-areas: "date status main" ". . actions";
    gap: 8px 12px;
  }
  .agenda-status-cell:empty { display: none; }
  .agenda-actions { justify-content: flex-end; }
  .agenda-month-nav { flex-wrap: wrap; }
  .calendar-filters { align-items: stretch; }
  .cal-author-filter, .cal-event-filter { width: 100%; }
}

@media (max-width: 650px) {
  .calendar-pagehead { align-items: stretch; gap: 10px; }
  .calendar-pagehead h1 { width: 100%; margin-bottom: 0; font-size: 22px; }
  .calendar-pagehead > .row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; width: 100%; }
  .calendar-pagehead > .row .btn { min-width: 0; padding: 9px 6px; text-align: center; font-size: 13px; }
  .calendar-pagehead > .row .btn.primary { grid-column: 1 / -1; min-height: 44px; }

  .calcard { padding: 7px; }
  .calcard .calgrid { display: grid; gap: 3px; }
  .calgrid .calhead { padding: 4px 0; font-size: 11px; }
  .calgrid .calday { height: 58px; min-height: 58px; padding: 4px 3px; border-radius: 6px; text-align: center; }
  .calgrid .calday.selected-day { border-color: var(--accent); background: #21304a; box-shadow: 0 0 0 1px var(--accent); }
  .calgrid .caldate { margin-bottom: 4px; font-size: 13px; line-height: 1; }
  .calgrid .calday .addhint { display: none; }
  .calgrid .calev {
    display: inline-block; width: 7px; height: 7px; min-width: 7px; min-height: 7px;
    margin: 1px; padding: 0; border: 0; border-radius: 50%; font-size: 0;
    line-height: 0; vertical-align: top; pointer-events: none;
  }
  .calgrid .calev > span, .calgrid .calev > small { display: none; }
  .calendar-filters { margin-top: 0; padding-top: 0; border-top: 0; gap: 10px; }
  .calendar-filters .callegend {
    width: 100%; flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding: 2px 1px 7px;
    scrollbar-width: thin; -webkit-overflow-scrolling: touch;
  }
  .calendar-filters .calfilter { flex: 0 0 auto; min-height: 38px; padding: 7px 11px; }
  .cal-author-filter, .cal-event-filter { min-width: 0; width: 100%; }
  .cal-author-filter select, .cal-event-filter select { min-height: 44px; font-size: 16px; }

  #koik-kirjed { min-height: 0; padding: 12px; }
  .mobile-day-filter {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin: 8px 0 12px; padding: 10px; border: 1px solid var(--accent);
    border-radius: 9px; background: #1c2534;
  }
  .mobile-day-filter[hidden] { display: none; }
  .mobile-day-filter > strong { white-space: nowrap; }
  .mobile-day-filter .row { justify-content: flex-end; }
  .mobile-day-filter .btn { padding: 7px 9px; font-size: 12px; }
  .agenda-section-head { margin-bottom: 6px; }
  .agenda-section-head h2 { font-size: 18px; }
  .agenda-month-nav { display: none; }
  .agenda-list { gap: 9px; }
  .agenda-list .agenda-item {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "date actions" "status status" "main main";
    gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
    background: var(--card2);
  }
  .agenda-list .agenda-item:not(.is-task) {
    grid-template-areas: "date actions" "main main";
  }
  .agenda-item:not(.is-task) .agenda-status-cell { display: none; }
  .agenda-date { font-size: 14px; }
  .agenda-status-cell { min-height: 28px; }
  .agenda-status-cell:empty { display: none; }
  .agenda-heading { flex-wrap: wrap; gap: 7px; }
  .agenda-kind, .agenda-status { min-height: 32px; padding: 6px 10px; }
  .agenda-title, .agenda-edit-btn, .agenda-text-details { flex: 1 0 100%; width: 100%; }
  .agenda-text-details summary { padding: 3px 0; }
  .agenda-text-full { line-height: 1.5; }
  .agenda-meta { margin-top: 9px; gap: 5px; }
  .agenda-pill, .agenda-meta .relation-pill { min-height: 32px; max-width: 100%; white-space: normal; }
  .agenda-actions { justify-content: flex-end; align-self: start; min-height: 28px; }
  .agenda-actions .linkbtn { min-width: 34px; min-height: 34px; font-size: 18px; }

}


/* Modaal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(8,10,14,.62);
  display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--card); border: 1px solid var(--line2); border-radius: 12px;
  box-shadow: 0 16px 50px rgba(0,0,0,.6); padding: 20px 22px; width: 420px; max-width: 94vw;
}
.modal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
.modal-head .linkbtn { font-size: 18px; color: var(--muted); }
.form-separator { display: flex; align-items: center; gap: 10px; margin: 2px 0 8px; }
.form-separator::before, .form-separator::after { content: ""; height: 1px; background: var(--line2); flex: 1; }
.task-edit-modal { width: 620px; max-height: 84vh; overflow-y: auto; overflow-x: hidden; }
.task-edit-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, .8fr); gap: 4px 14px; }
.task-edit-relations { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.task-edit-grid > label { min-width: 0; }
.task-edit-grid input, .task-edit-grid select { width: 100%; min-width: 0; }
.task-edit-grid .wide { grid-column: 1 / -1; }
@media (max-width: 650px) {
  .task-edit-grid, .task-edit-relations { grid-template-columns: 1fr; }
  .task-edit-grid .wide { grid-column: auto; }
}

/* Libisev paneel (asutuse kiirloomine) */
.drawer-overlay { position: fixed; inset: 0; z-index: 110; background: rgba(8,10,14,.62); display: flex; justify-content: flex-end; }
.drawer-overlay[hidden] { display: none; }
.drawer {
  background: var(--card); border-left: 1px solid var(--line2); width: 460px; max-width: 94vw;
  height: 100%; overflow-y: auto; padding: 22px 24px; box-shadow: -14px 0 50px rgba(0,0,0,.55);
}
.drawer .grid2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 800px) { .drawer { width: 100%; } .drawer .grid2 { grid-template-columns: 1fr; } }
.modal-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.mtab {
  flex: 1; padding: 8px 10px; border: 1px solid var(--line2); border-radius: 8px;
  background: #191d24; color: #aeb6c3; cursor: pointer; font: inherit; font-weight: 600;
}
.mtab:hover { background: #1e2530; }
.mtab.active { background: #1c2534; border-color: var(--accent); color: #cfe0fb; }

/* Sakid */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 2px solid var(--line2); flex-wrap: wrap; }
.tab { padding: 8px 14px; font-weight: 600; color: #9aa3b0; border-radius: 8px 8px 0 0; }
.tab:hover { background: #22262d; text-decoration: none; }
.tab.active { background: var(--card); border: 2px solid var(--line2); border-bottom: 2px solid var(--card); margin-bottom: -2px; color: var(--text); }

/* Sisselogimine */
.loginpage { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #111318; }
.loginbox { background: var(--card); border: 1px solid var(--line2); border-radius: 14px; padding: 34px 38px; width: 360px; max-width: 92vw; box-shadow: 0 14px 50px rgba(0,0,0,.55); }
.loginbox h1 { text-align: center; font-size: 22px; }
.userlist { display: flex; flex-direction: column; gap: 8px; }
.userbtn {
  display: block; padding: 12px; text-align: center; border: 1px solid var(--line2);
  border-radius: 10px; font-weight: 700; color: var(--text); background: #22252c;
}
.userbtn:hover { background: #1c2534; border-color: var(--accent); text-decoration: none; }
.pininput { width: 100%; font-size: 26px; text-align: center; letter-spacing: 10px; margin-bottom: 12px; }

/* Mobiil */
@media (max-width: 800px) {
  .app { flex-direction: column; }
  .mobilebar {
    display: flex; align-items: center; gap: 10px; background: #111318; color: #fff;
    padding: 10px 14px; position: sticky; top: 0; z-index: 40; border-bottom: 1px solid var(--line);
  }
  .mobilebar .mbrand { color: #fff; font-weight: 700; }
  .menubtn { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; }
  .sidebar { display: none; position: fixed; z-index: 50; height: auto; width: 260px; top: 44px; bottom: 0; overflow-y: auto; }
  .sidebar.open { display: flex; }
  .content { padding: 14px 12px 40px; }
  .twocol { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .calday { height: 72px; min-height: 72px; }
  .calev { font-size: 10px; }
  table.list { display: block; overflow-x: auto; }
  .doneform, .droppanel { position: fixed; left: 5vw; right: 5vw; width: auto; }
}

@media (max-width: 650px) {
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal, .task-edit-modal {
    width: 100%; max-width: none; max-height: 100dvh; min-height: 100dvh;
    border: 0; border-radius: 0; padding: 16px; overflow-y: auto;
  }
  .modal-head {
    position: sticky; top: -16px; z-index: 2; margin: -16px -16px 14px;
    padding: 15px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  }
  .modal-head .linkbtn { min-width: 42px; min-height: 42px; }
  .modal-tabs .mtab { min-height: 44px; }
  .modal input, .modal select, .modal textarea { font-size: 16px; }
  .modal .row.right {
    position: sticky; bottom: -16px; margin: 10px -16px -16px; padding: 12px 16px;
    background: var(--card); border-top: 1px solid var(--line);
  }
  .modal .row.right .btn { min-height: 44px; flex: 1; }
}
