/* ==========================================================
   DarbaVieta Čeki — stils pēc darbavieta.rocks parauga
   ========================================================== */
:root {
    --red: #E2231A;
    --red-dark: #B81B14;
    --ink: #141414;
    --ink-soft: #6b6963;
    --paper: #ffffff;
    --bg: #f6f5f2;
    --line: #e5e2dc;
    --ok: #1a7f37;
    --radius: 12px;
    --font-body: "Inter Tight", system-ui, sans-serif;
    --font-display: "Newsreader", Georgia, serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 16px;
    color: var(--ink);
    background: var(--bg);
}

/* --- Virsraksti / wordmark --- */
.wordmark {
    font-weight: 600;
    letter-spacing: -0.01em;
    font-size: 1.15rem;
}
.wordmark em, h1 em, h2 em {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    color: var(--red);
}
h1 {
    font-size: clamp(1.5rem, 4vw, 2.1rem);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0 0 1rem;
}

/* --- Topbar --- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.25rem;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: 0.9rem; }
.user-chip {
    font-size: 0.85rem;
    color: var(--ink-soft);
}
.link-quiet {
    color: var(--ink);
    text-decoration: none;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--line);
}
.link-quiet:hover { color: var(--red); border-color: var(--red); }

.wrap { max-width: 860px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

/* --- Pievienošanas panelis --- */
.add-panel { margin-bottom: 2.25rem; }
.add-buttons { display: flex; flex-wrap: wrap; gap: 0.75rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 500;
    padding: 0.8rem 1.4rem;
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-outline { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn-outline:hover { border-color: var(--red); color: var(--red); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-small { font-size: 0.85rem; padding: 0.45rem 0.9rem; }
.btn-full { width: 100%; }
.btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

.upload-status {
    margin-top: 0.9rem;
    padding: 0.7rem 1rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 0.9rem;
}
.upload-status.err { border-color: var(--red); color: var(--red); }

/* --- Mēneši --- */
.month { margin-bottom: 2.5rem; }
.month-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-bottom: 0.9rem;
}
.month-head h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.01em;
}
.month-head .year { color: var(--ink-soft); font-weight: 400; }
.month-meta { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.month-count { font-size: 0.85rem; color: var(--ink-soft); }
.month-total {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* --- Kartītes --- */
.cards { display: flex; flex-direction: column; gap: 0.6rem; }
.card {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.card:hover, .card:focus-visible { border-color: var(--red); outline: none; }
.card.is-booked { opacity: 0.6; }
.card-thumb {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pdf-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--red);
    border: 1px solid var(--red);
    border-radius: 4px;
    padding: 0.1rem 0.3rem;
}
.card-body { flex: 1; min-width: 0; }
.card-vendor {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card-date { font-size: 0.85rem; color: var(--ink-soft); }
.card-sum {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.chip {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    white-space: nowrap;
}
.chip-warn { background: #fdeceb; color: var(--red); }
.chip-ok { background: #e8f3ec; color: var(--ok); }

.empty {
    text-align: center;
    color: var(--ink-soft);
    padding: 3rem 1rem;
}

/* --- Modālis --- */
.modal { position: fixed; inset: 0; z-index: 50; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 20, 20, 0.55); }
.modal-box {
    position: relative;
    background: var(--paper);
    max-width: 560px;
    margin: 4vh auto;
    max-height: 92vh;
    border-radius: var(--radius);
    overflow-y: auto;
    padding: 1rem 1.25rem 1.5rem;
}
@media (max-width: 620px) {
    .modal-box { margin: 0; max-width: none; height: 100%; max-height: none; border-radius: 0; }
}
.modal-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    position: sticky;
    top: 0;
    background: var(--paper);
    padding: 0.25rem 0;
}
.modal-close {
    border: none;
    background: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--ink-soft);
    padding: 0.25rem 0.5rem;
}
.modal-close:hover { color: var(--red); }

.tabs { display: flex; gap: 0.25rem; }
.tab {
    border: none;
    background: none;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    cursor: pointer;
    color: var(--ink-soft);
}
.tab.is-active { background: var(--ink); color: #fff; }
.tab:hover:not(.is-active) { color: var(--red); }

#preview img { width: 100%; border-radius: 8px; }
#preview iframe { width: 100%; height: 65vh; border: 1px solid var(--line); border-radius: 8px; }

/* --- Izvilkums — kā papīra čeks (zāģīta apakšmala) --- */
.receipt {
    background: var(--bg);
    padding: 1.5rem 1.5rem 2rem;
    font-variant-numeric: tabular-nums;
    -webkit-clip-path: polygon(0 0, 100% 0, 100% calc(100% - 10px),
        95% 100%, 90% calc(100% - 10px), 85% 100%, 80% calc(100% - 10px),
        75% 100%, 70% calc(100% - 10px), 65% 100%, 60% calc(100% - 10px),
        55% 100%, 50% calc(100% - 10px), 45% 100%, 40% calc(100% - 10px),
        35% 100%, 30% calc(100% - 10px), 25% 100%, 20% calc(100% - 10px),
        15% 100%, 10% calc(100% - 10px), 5% 100%, 0 calc(100% - 10px));
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 10px),
        95% 100%, 90% calc(100% - 10px), 85% 100%, 80% calc(100% - 10px),
        75% 100%, 70% calc(100% - 10px), 65% 100%, 60% calc(100% - 10px),
        55% 100%, 50% calc(100% - 10px), 45% 100%, 40% calc(100% - 10px),
        35% 100%, 30% calc(100% - 10px), 25% 100%, 20% calc(100% - 10px),
        15% 100%, 10% calc(100% - 10px), 5% 100%, 0 calc(100% - 10px));
}
.receipt-vendor {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1.35rem;
    margin-bottom: 1rem;
}
.receipt-line {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px dashed var(--line);
    font-size: 0.95rem;
}
.receipt-line span { color: var(--ink-soft); }
.receipt-total {
    display: flex;
    justify-content: space-between;
    padding: 0.7rem 0 0.3rem;
    font-size: 1.15rem;
    font-weight: 600;
}
.receipt-total b { color: var(--red); }
.receipt-summary { color: var(--ink-soft); font-size: 0.9rem; margin: 0.9rem 0 0; }

/* --- Labošanas forma --- */
.edit-form label {
    display: block;
    font-size: 0.8rem;
    color: var(--ink-soft);
    margin-bottom: 0.75rem;
}
.edit-form input, .edit-form select,
.login-card input {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--ink);
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
}
.edit-form input:focus, .edit-form select:focus, .login-card input:focus {
    outline: none;
    border-color: var(--red);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.75rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 0.75rem; }
.edit-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.5rem;
}
.edit-actions .spacer { flex: 1; }
.booked-toggle {
    display: flex !important;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem !important;
    color: var(--ink) !important;
    margin: 0 !important;
}
.booked-toggle input { width: auto; margin: 0; }

/* --- Login --- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}
.login-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 2rem 1.75rem;
    width: 100%;
    max-width: 380px;
}
.login-card .wordmark { font-size: 1.4rem; margin-bottom: 0.35rem; }
.login-sub { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 1.5rem; }
.login-card label {
    display: block;
    font-size: 0.8rem;
    color: var(--ink-soft);
    margin-bottom: 0.9rem;
}
.alert {
    background: #fdeceb;
    color: var(--red);
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* --- AI kļūdas ziņojums --- */
.ai-error {
    background: #fdeceb;
    border-radius: 8px;
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
}
.ai-error p {
    color: var(--red);
    font-size: 0.9rem;
    margin: 0 0 0.6rem;
    word-break: break-word;
}

/* --- Bankas izrakstu rinda --- */
.bank-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin: -0.2rem 0 0.8rem;
    font-size: 0.85rem;
}
.bank-title { color: var(--ink-soft); }
.bank-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.3rem 0.8rem;
    color: var(--ink);
    text-decoration: none;
    font-weight: 500;
}
.bank-chip:hover { border-color: var(--red); color: var(--red); }
.bank-add, .bank-change { cursor: pointer; }
.bank-add {
    display: inline-flex;
    border: 1px dashed var(--ink-soft);
    border-radius: 999px;
    padding: 0.3rem 0.8rem;
    color: var(--ink-soft);
    font-weight: 500;
}
.bank-add:hover { border-color: var(--red); color: var(--red); }
.bank-change {
    color: var(--ink-soft);
    border-bottom: 1px solid var(--line);
}
.bank-change:hover { color: var(--red); border-color: var(--red); }

/* --- Modāļa augšējās darbības --- */
.modal-top-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}
