﻿/* е-Вход: прост Material стил без външни библиотеки */
:root {
    --primary: #3f51b5;
    --primary-dark: #303f9f;
    --on-primary: #fff;
    --surface: #fff;
    --bg: #f4f5fa;
    --text: #1d1b20;
    --muted: #6b6b76;
    --line: #e0e0e8;
    --ok: #2e7d32;
    --ok-bg: #e8f5e9;
    --error: #c62828;
    --error-bg: #ffebee;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); }
h1 { font-size: 24px; font-weight: 500; margin: 8px 0 16px; }
h2 { font-size: 18px; font-weight: 500; margin: 0 0 12px; }

/* горна лента */
.appbar { background: var(--primary); color: var(--on-primary); display: flex; flex-wrap: wrap; align-items: center;
          gap: 4px 16px; padding: 8px 16px; box-shadow: 0 2px 4px rgba(0,0,0,.2); position: relative; z-index: 10; }
.appbar .brand { display: block; margin-right: 8px; line-height: 0; }
.appbar .brand img { width: 40px; height: 40px; border-radius: 8px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.appbar .brand:hover img { box-shadow: 0 0 0 2px rgba(255,255,255,.6); }
.appbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; flex: 1; }
.appbar nav > a, .appbar summary { color: rgba(255,255,255,.85); text-decoration: none; padding: 6px 12px; border-radius: 16px; font-size: 14px; }
.appbar nav > a:hover, .appbar summary:hover { background: rgba(255,255,255,.12); }
.appbar nav > a.active, .appbar .dropdown.active > summary { background: rgba(255,255,255,.22); color: #fff; }
.appbar .fas { margin-right: 4px; }

/* падащи менюта: <details class="dropdown"><summary>…</summary><div class="dropdown-menu">…</div></details> */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; cursor: pointer; user-select: none; display: inline-block; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown > summary::after { content: ""; display: inline-block; margin-left: 6px; vertical-align: 2px;
                             border: 4px solid transparent; border-top-color: currentColor; border-bottom: 0; }
.dropdown[open] > summary { background: rgba(255,255,255,.22); color: #fff; }
.dropdown-menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 200px; background: var(--surface); color: var(--text);
                 border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.18); padding: 6px 0; }
.dropdown-menu a, .dropdown-menu .menu-button { display: block; width: 100%; padding: 9px 16px; color: var(--text); text-decoration: none;
                 font: inherit; font-size: 14px; text-align: left; background: none; border: 0; cursor: pointer; }
.dropdown-menu a:hover, .dropdown-menu .menu-button:hover { background: #eef0f8; }
.dropdown-menu a.active { color: var(--primary); font-weight: 500; background: #e8eaf6; }
.user-menu { margin-left: auto; }
.user-menu .dropdown-menu { left: auto; right: 0; }
.user-menu > summary { color: #fff; }

/* бутонът ☰ се вижда само на телефон */
.nav-toggle { display: none; }
.nav-burger { display: none; color: #fff; font-size: 20px; padding: 4px 10px; cursor: pointer; border-radius: 8px; }
.nav-burger:hover { background: rgba(255,255,255,.12); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* карти и подредба */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 20px; margin-bottom: 16px; overflow-x: auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 16px; }
.cards .card { margin: 0; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 500; }
.narrow { max-width: 440px; }
main.centered { max-width: 440px; padding-top: 48px; }
main.centered h1 { text-align: center; }
.narrow .field { margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 13px; }
.right { text-align: right; }
.hidden { display: none !important; }

/* съобщения */
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.error { background: var(--error-bg); color: var(--error); }

/* полета */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; align-items: end; }
.form .wide { grid-column: 1 / -1; }
.field label, .field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month],
input[type=datetime-local], input[type=tel], select, textarea {
    width: 100%; padding: 9px 12px; font: inherit; color: inherit; background: #fff;
    border: 1px solid #c4c4cc; border-radius: 6px; outline: none;
}
/* собствена стрелка на падащите списъци, с повече място отдясно */
select { -webkit-appearance: none; appearance: none; padding-right: 38px; cursor: pointer;
         background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b6b76' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
         background-repeat: no-repeat; background-position: right 14px center; background-size: 12px 8px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
textarea { min-height: 180px; resize: vertical; font-family: Consolas, monospace; font-size: 14px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); vertical-align: middle; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.checks label { color: var(--text); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.actions + .card { margin-top: 16px; }

/* бутони */
.btn, input[type=submit].btn, button.btn {
    display: inline-block; border: 0; border-radius: 20px; padding: 9px 20px; font: inherit; font-weight: 500;
    background: var(--primary); color: #fff; cursor: pointer; text-decoration: none; line-height: 1.4;
}
.btn:hover { background: var(--primary-dark); }
.btn.outline, input[type=submit].btn.outline { background: transparent; color: var(--primary); box-shadow: inset 0 0 0 1px #c4c4cc; }
.btn.outline:hover, input[type=submit].btn.outline:hover { background: rgba(63,81,181,.08); }
.btn.text, input[type=submit].btn.text { background: transparent; color: var(--primary); padding: 4px 10px; }
.btn.text:hover, input[type=submit].btn.text:hover { background: rgba(63,81,181,.08); }
.btn.text.on-dark, input[type=submit].btn.text.on-dark { color: #fff; }
.btn.text.on-dark:hover { background: rgba(255,255,255,.15); }
.btn.danger { color: var(--error); }

/* таблици */
table.grid { border-collapse: collapse; width: 100%; font-size: 14px; }
table.grid th { text-align: left; font-weight: 600; color: var(--primary-dark); background: #e8eaf6; border-bottom: 1px solid #c5cae9; padding: 9px 8px; white-space: nowrap; }
table.grid th:first-child { border-top-left-radius: 8px; }
table.grid th:last-child { border-top-right-radius: 8px; }
table.grid td { border-bottom: 1px solid var(--line); padding: 8px; vertical-align: middle; }
table.grid td .btn.text { padding: 2px 8px; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.num, table.grid th.num { text-align: right; white-space: nowrap; }
table.grid tr.voided td { color: #999; text-decoration: line-through; }
table.grid tr.voided td.reason { text-decoration: none; }
table.grid tfoot td { font-weight: 500; border-top: 2px solid var(--line); }
/* ред „Общо“ (FooterStyle-CssClass="total") */
table.grid tr.total td { background: #e8eaf6; color: var(--primary-dark); font-weight: 600; border-top: 2px solid #c5cae9; border-bottom: 0; }
table.grid tr.total td:first-child { border-bottom-left-radius: 8px; }
table.grid tr.total td:last-child { border-bottom-right-radius: 8px; }
.debt { color: var(--error); font-weight: 500; }
.prepaid { color: var(--ok); font-weight: 500; }

/* табове над таблица */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.tabs { display: flex; gap: 4px; }
.tab { padding: 10px 18px; border-radius: 10px 10px 0 0; text-decoration: none; color: var(--muted); font-weight: 500; }
.tab:hover { background: rgba(63,81,181,.08); }
.tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.tab .count { display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 4px; border-radius: 11px; background: #e8eaf6; color: var(--primary-dark); font-size: 12px; text-align: center; }
.toolbar .btn { margin-bottom: 8px; }
.card.tab-card { border-top-left-radius: 0; }

/* модален прозорец */
dialog.modal { border: 0; border-radius: var(--radius); padding: 20px 24px; width: min(640px, calc(100vw - 24px));
               max-height: calc(100vh - 24px); box-shadow: 0 12px 40px rgba(0,0,0,.3); color: var(--text); }
dialog.modal::backdrop { background: rgba(20,20,40,.45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; }
.icon-btn { background: none; border: 0; font-size: 18px; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: #eef0f8; color: var(--text); }
.icon-btn:focus { outline: none; }
.icon-btn:focus-visible { box-shadow: 0 0 0 2px var(--primary); }
.rows { display: grid; gap: 12px; }
.rows .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
textarea.plain { min-height: 80px; font: inherit; }
@media (max-width: 600px) { .rows .row2 { grid-template-columns: 1fr; } dialog.modal { padding: 16px; } }

dialog.modal.wide { width: min(860px, calc(100vw - 24px)); }
.hint span { margin-right: 4px; }
/* бутон, който изглежда като линк (изпраща формата, напр. „Изчисли разпределението“) */
.link-button, input[type=submit].link-button { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; font-weight: 500;
               color: var(--primary); text-decoration: underline; cursor: pointer; }
.link-button:hover { color: var(--primary-dark); }

/* страница с ново съобщение: отметката вляво, бутонът вдясно */
.actions.spread { justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 16px; }
.check label { color: var(--text); }

/* страници (журнал) */
.pager { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; align-items: center; }
.pager a.current { background: var(--primary); color: #fff; }
.pager a.disabled { color: #b0b0b8; pointer-events: none; }

.chip { display: inline-block; padding: 1px 10px; border-radius: 12px; background: #e8eaf6; color: var(--primary-dark); font-size: 12px; }

/* съобщения (Markdown) */
.markdown h1, .markdown h2, .markdown h3 { font-weight: 500; margin: 16px 0 8px; }
.markdown h1 { font-size: 22px; }
.markdown table { border-collapse: collapse; }
.markdown td, .markdown th { border: 1px solid var(--line); padding: 4px 8px; }
.markdown img { max-width: 100%; }
.preview { border: 1px dashed #c4c4cc; border-radius: 8px; padding: 8px 16px; margin-top: 12px; }

@media (max-width: 800px) {
    .nav-burger { display: block; order: 2; }
    .user-menu { order: 3; }
    .appbar nav { display: none; order: 4; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: 6px; }
    .nav-toggle:checked ~ nav { display: flex; }
    .appbar nav > a, .appbar nav summary { display: block; padding: 10px 12px; }
    .appbar nav .dropdown-menu { position: static; box-shadow: none; background: rgba(255,255,255,.1); margin: 4px 0 0 12px; }
    .appbar nav .dropdown-menu a { color: #fff; }
    .appbar nav .dropdown-menu a:hover, .appbar nav .dropdown-menu a.active { background: rgba(255,255,255,.15); color: #fff; }
}

@media (max-width: 600px) {
    main { padding: 10px; }
    .card { padding: 12px; }
    h1 { font-size: 20px; }
    .user-menu .user-name { display: none; }
}
