/* MK Factory — administrace fakturačního systému */

:root {
    --sidebar-bg: #1b2733;
    --sidebar-text: #aebac6;
    --sidebar-active: #ffffff;
    --accent: #1f6feb;
    --accent-dark: #175bc4;
    --bg: #f2f4f7;
    --panel: #ffffff;
    --border: #dde2e8;
    --text: #1d2733;
    --muted: #66707c;
    --danger: #c0392b;
    --success: #1d7a3d;
    --warning: #9a6700;
    --radius: 6px;
    --focus-ring: 0 0 0 3px rgba(31, 111, 235, 0.35);
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }

code { background: #eef1f5; padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.85em; }

.muted { color: var(--muted); }
.mt { margin-top: 1.5rem; }

.sr-only {
    position: absolute; width: 1px; height: 1px;
    margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- layout ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.1rem 0.9rem;
    gap: 1rem;
}

.sidebar-brand { display: flex; align-items: center; gap: 0.5rem; padding: 0 0.35rem; }

.brand-mark {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
    border-radius: 5px;
    letter-spacing: 0.03em;
}

.brand-name { color: #fff; font-weight: 600; letter-spacing: 0.02em; }

.sidebar-org {
    font-size: 0.82rem;
    padding: 0.4rem 0.6rem;
    background: rgba(255, 255, 255, 0.07);
    border-radius: var(--radius);
    color: #d6dde4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-nav a {
    color: var(--sidebar-text);
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius);
    font-size: 0.92rem;
}

.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; text-decoration: none; }

.sidebar-nav a.active { background: var(--accent); color: var(--sidebar-active); }

.sidebar-nav a:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.sidebar-footer {
    margin-top: auto;
    font-size: 0.82rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 0.75rem;
}

.sidebar-user { color: #d6dde4; margin-bottom: 0.35rem; }

.sidebar-actions { display: flex; flex-direction: column; gap: 0.2rem; align-items: flex-start; }

.sidebar-actions a { color: var(--sidebar-text); }

.main {
    flex: 1;
    padding: 1.5rem 2rem 3rem;
    min-width: 0;
    max-width: 1200px;
}

/* ---------- hlavička stránky ---------- */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.page-subtitle { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.35rem; }

.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.header-actions form { margin: 0; }

/* ---------- panely ---------- */

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.25rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    align-items: start;
}

.detail-grid .panel { margin-bottom: 0; }

.detail-grid + .panel { margin-top: 1.25rem; }

/* ---------- statistiky ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
}

.stat-card.stat-danger { border-left: 4px solid var(--danger); }

.stat-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.stat-value { font-size: 1.7rem; font-weight: 700; margin: 0.15rem 0; }

.stat-value-sm { font-size: 1.15rem; }

.stat-detail { font-size: 0.83rem; color: var(--muted); }

/* ---------- tabulky ---------- */

.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }

.table th {
    text-align: left;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    border-bottom: 2px solid var(--border);
    padding: 0.5rem 0.6rem;
    white-space: nowrap;
}

.table td { border-bottom: 1px solid var(--border); padding: 0.55rem 0.6rem; vertical-align: top; }

.table tbody tr:hover { background: #f7f9fb; }

.table .num, .table th.num { text-align: right; white-space: nowrap; }

.table .actions { text-align: right; white-space: nowrap; width: 1%; }

.table tfoot td { border-bottom: none; border-top: 2px solid var(--border); }

/* ---------- štítky stavů ---------- */

.badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    white-space: nowrap;
}

.badge-draft { background: #e9edf2; color: #4a5560; }
.badge-issued { background: #dbeafe; color: #1d4ed8; }
.badge-partially_paid { background: #fdf0d3; color: var(--warning); }
.badge-paid { background: #d8f0df; color: var(--success); }
.badge-overdue { background: #fadbd7; color: var(--danger); }
.badge-cancelled { background: #efe3f5; color: #7d3c98; }
.badge-received { background: #dbeafe; color: #1d4ed8; }
.badge-approved { background: #d7f0f7; color: #0e7490; }
.badge-rejected { background: #efe3f5; color: #7d3c98; }

/* ---------- formuláře ---------- */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.9rem 1.25rem;
}

.form-grid-4 { grid-template-columns: repeat(4, 1fr); }

.field { display: flex; flex-direction: column; gap: 0.25rem; }

.field.span-2 { grid-column: span 2; }

/* atribut hidden musí přebít display: flex pole (přepínané části formuláře) */
.field[hidden] { display: none; }

.field label,
.field-group legend { font-size: 0.85rem; font-weight: 600; }

/* skupina přepínačů (např. způsob zadání odběratele) */
.field-group { border: 0; padding: 0; margin: 0; min-width: 0; }

.field-group legend { padding: 0; margin-bottom: 0.25rem; }

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input[type="date"],
.field select,
.field textarea {
    font: inherit;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    width: 100%;
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

.field input[aria-invalid="true"] { border-color: var(--danger); }

.field-checkbox { justify-content: flex-end; }

.field-checkbox label { font-weight: 400; display: flex; align-items: center; gap: 0.45rem; }

.field-error { color: var(--danger); font-size: 0.82rem; margin: 0; }

.field-hint { color: var(--muted); font-size: 0.8rem; margin: 0; }

.form-actions { display: flex; gap: 0.6rem; margin-top: 1.25rem; }

.inline-form { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }

.inline-form .field { min-width: 130px; }

.section-title { margin-top: 1.5rem; }

/* výběr dodavatele (existující / nový podle IČO) */

.supplier-picker {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem 1.1rem;
    margin: 0 0 1.25rem;
}

.supplier-picker legend { font-size: 0.85rem; font-weight: 600; padding: 0 0.35rem; }

.mode-choice { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 0.9rem; }

.mode-choice label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.mode-panel[hidden] { display: none; }

.input-with-button { display: flex; gap: 0.5rem; align-items: stretch; }

.input-with-button input { flex: 1; min-width: 0; }

.input-with-button .btn { white-space: nowrap; }

.ares-status { font-size: 0.83rem; color: var(--muted); margin: 0.35rem 0 0; min-height: 1.2em; }

/* položky faktury */

.items-table td { vertical-align: top; }
.items-table input, .items-table select {
    font: inherit;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
}
.items-table input:focus-visible, .items-table select:focus-visible {
    outline: none; border-color: var(--accent); box-shadow: var(--focus-ring);
}
.w-qty { width: 110px; }
.w-unit { width: 80px; }
.w-price { width: 130px; }
.w-vat { width: 100px; }
.w-remove { width: 40px; text-align: center; }

/* ---------- tlačítka ---------- */

.btn {
    display: inline-block;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { background: #f3f5f8; text-decoration: none; }

.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-primary:hover { background: var(--accent-dark); }

.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }

.btn-danger:hover { background: #fdf1ef; }

.btn-block { width: 100%; }

.link-button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--accent);
    cursor: pointer;
}

.link-button:hover { text-decoration: underline; }

.link-button:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 3px; }

.link-button.danger { color: var(--danger); }

/* ---------- flash zprávy ---------- */

.flash {
    padding: 0.65rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.92rem;
    border: 1px solid transparent;
}

.flash-success { background: #e5f5ea; color: var(--success); border-color: #bfe5cb; }

.flash-error { background: #fdeceb; color: var(--danger); border-color: #f5c6c0; }

/* ---------- filtry ---------- */

.filter-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-tabs a {
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    font-size: 0.88rem;
    color: var(--muted);
}

.filter-tabs a:hover { background: #e8ecf1; text-decoration: none; }

.filter-tabs a.active { background: var(--sidebar-bg); color: #fff; }

/* ---------- detail ---------- */

.detail-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.3rem 1.25rem;
    margin: 0 0 1rem;
}

.detail-list dt { color: var(--muted); font-size: 0.88rem; }

.detail-list dd { margin: 0; font-size: 0.92rem; }

.attachment-list { list-style: none; margin: 0 0 1rem; padding: 0; }

.attachment-list li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
}

.attachment-list form { margin-left: auto; }

.logo-preview {
    max-height: 80px;
    max-width: 240px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.4rem;
    background: #fff;
}

/* ---------- stránkování ---------- */

.pagination { display: flex; gap: 0.25rem; margin-top: 1rem; flex-wrap: wrap; }

.page-link {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.88rem;
    color: var(--text);
}

.page-link:hover { background: #f3f5f8; text-decoration: none; }

.page-link.current { background: var(--accent); border-color: var(--accent); color: #fff; }

.page-link.disabled { color: #aab3bd; pointer-events: none; }

/* ---------- přihlášení ---------- */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    margin: 0;
}

.auth-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem 2.25rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 10px 30px rgba(27, 39, 51, 0.08);
}

.auth-brand { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.25rem; }

.auth-brand .brand-name { color: var(--text); font-weight: 700; }

.auth-card h1 { font-size: 1.2rem; margin-bottom: 1.25rem; }

.auth-card .field { margin-bottom: 0.9rem; }

.org-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }

.org-choice {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    width: 100%;
    text-align: left;
    font: inherit;
    padding: 0.7rem 0.9rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

.org-choice:hover { border-color: var(--accent); }

.org-choice:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.org-name { font-weight: 600; }

/* ---------- responzivita ---------- */

@media (max-width: 900px) {
    .app { flex-direction: column; }

    .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; }

    .sidebar-nav { flex-direction: row; flex-wrap: wrap; }

    .sidebar-footer { margin-top: 0; margin-left: auto; border-top: none; padding-top: 0; }

    .main { padding: 1rem; }

    .detail-grid { grid-template-columns: 1fr; }

    .form-grid, .form-grid-4 { grid-template-columns: 1fr; }

    .field.span-2 { grid-column: span 1; }

    .items-table { display: block; overflow-x: auto; }
}
