:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --ink: #1f2430;
    --muted: #8a91a0;
    --line: #e4e7ec;
    --accent: #2f6df6;
    --accent-ink: #ffffff;
    --ok: #1f9d6b;
    --danger: #d64545;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(20, 25, 40, .06), 0 8px 24px rgba(20, 25, 40, .05);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-weight: 400; }

/* Topbar */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; padding: 12px 20px; background: var(--card);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 32px; }
.brand-name { font-weight: 600; }
.nav { display: flex; gap: 18px; }
.nav a { color: var(--ink); font-weight: 500; }

/* Layout */
.wrap { max-width: 920px; margin: 24px auto 120px; padding: 0 16px; }

/* Cards */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 16px; font-size: 17px; }
.supplier .supplier-grid { display: flex; flex-direction: column; gap: 2px; color: var(--ink); }

/* Form grid */
.grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.field-wide { grid-column: span 2; }

input[type=text], input[type=password], input[type=date], select {
    width: 100%; height: 40px; padding: 0 11px; font-size: 14.5px; color: var(--ink);
    background: #fff; border: 1px solid var(--line); border-radius: 9px;
    outline: none; transition: border-color .12s, box-shadow .12s;
    font-family: inherit; line-height: normal;
}
input[type=date] { cursor: text; }
input[type=date]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .55; }
/* Normalise the native select so it matches input height exactly. */
select {
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    padding-right: 30px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a91a0' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 11px center;
}
input:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 109, 246, .15);
}

/* Items */
.item {
    display: grid; grid-template-columns: 1fr 80px 130px 110px 32px;
    gap: 10px; align-items: end; padding: 10px 0; border-bottom: 1px dashed var(--line);
}
.item:last-of-type { border-bottom: 0; }
.field-sm, .field-name { min-width: 0; }
.btn-remove {
    height: 38px; width: 32px; border: 1px solid var(--line); background: #fff;
    border-radius: 9px; color: var(--danger); font-size: 18px; cursor: pointer; line-height: 1;
}
.btn-remove:hover { background: #fff1f1; border-color: var(--danger); }

/* ARES IČO lookup */
.ares-row { display: flex; gap: 10px; align-items: stretch; }
.ares-input { position: relative; flex: 1; }
.ares-input input { padding-right: 34px; }
.ares-ok {
    position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
    color: var(--ok); font-weight: 700; font-size: 16px; pointer-events: none;
}
.ares-row .btn { flex: none; }

/* Autocomplete */
.autocomplete { position: relative; margin-bottom: 14px; }
.suggestions {
    list-style: none; margin: 4px 0 0; padding: 4px; position: absolute; z-index: 20;
    top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line);
    border-radius: 10px; box-shadow: var(--shadow); max-height: 260px; overflow: auto;
}
.suggestions li { padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.suggestions li:hover, .suggestions li.active { background: #eef3ff; }
.suggestions li small { color: var(--muted); }

/* Summary */
.summary-row { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.summary-row .field { max-width: 160px; }
.totals { margin-left: auto; min-width: 220px; }
.totals > div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 2px solid var(--line); margin-top: 6px; padding-top: 8px; font-size: 18px; }
.totals span { color: var(--muted); }

/* Buttons */
.btn {
    display: inline-block; padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
    font-size: 15px; font-weight: 600; cursor: pointer; text-align: center;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(.95); text-decoration: none; }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-secondary { background: #fff; color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { text-decoration: none; }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--line); }
.btn-ghost:hover { background: #f0f4ff; }

/* Sticky action bar */
.action-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    display: flex; gap: 16px; justify-content: center; align-items: center;
    padding: 12px 24px; background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(6px); border-top: 1px solid var(--line);
}
/* Centered modal popups (generation confirmation + errors) */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(20, 25, 40, .35); backdrop-filter: blur(2px);
    opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s;
}
.modal-backdrop.show { opacity: 1; visibility: visible; }

.modal {
    position: fixed; top: 50%; left: 50%; z-index: 60;
    width: min(420px, 92vw);
    display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
    background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--ok);
    border-radius: 16px; box-shadow: 0 20px 60px rgba(20, 25, 40, .25);
    padding: 28px 24px 22px;
    opacity: 0; visibility: hidden;
    transform: translate(-50%, -48%) scale(.98);
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
.modal.show { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }
.modal-error { border-top-color: var(--danger); }
.modal .toast-icon {
    flex: none; width: 44px; height: 44px; border-radius: 50%;
    background: var(--ok); color: #fff; font-weight: 700;
    display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.modal-error .toast-icon { background: var(--danger); }
.modal .toast-body strong { font-size: 17px; }
.modal-text { margin: 6px 0 0; font-size: 14.5px; color: var(--ink); }
.modal .btn { margin-top: 8px; min-width: 130px; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Alerts */
.alert { background: #fff1f1; color: var(--danger); border: 1px solid #f3c8c8; padding: 10px 12px; border-radius: 9px; margin-bottom: 14px; font-size: 14px; }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.table th { color: var(--muted); font-weight: 600; }
.table .right { text-align: right; }

/* Login */
.login-card {
    max-width: 360px; margin: 8vh auto; background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px; text-align: center;
}
.login-logo { height: 48px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin: 8px 0 2px; }
.login-card form { margin-top: 18px; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card .btn { margin-top: 8px; }

/* Responsive */
@media (max-width: 640px) {
    .grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .item { grid-template-columns: 1fr 1fr; }
    .item .field-name { grid-column: span 2; }
    .btn-remove { width: 100%; }
    .totals { margin-left: 0; }
}
