/* ==========================================================================
   MedGyn — Administrace (admin.medgyn.cz)
   Vizuální styl vychází z docs/BRAND_MANUAL.md a docs/DESIGN_SYSTEM.md
   ========================================================================== */

:root {
    --background: #E8E1D4;
    --background-soft: #F7F5F0;
    --card: #DED5C4;
    --secondary: #D4CAB8;
    --primary: #214631;
    --primary-press: #1b3a28;
    --foreground: #1B3023;
    --muted: #4F5948;
    --accent: #748A68;
    --accent-warm: #C3B79F;
    --border: #BFB5A4;
    --danger: #a3342b;
    --danger-bg: #f4e3e0;
    --ok: #2f6b46;
    --ok-bg: #e4efe6;
    --radius-lg: 1.25rem;
    --radius-md: 1rem;
    --radius-sm: 0.6rem;
    --shadow-card:
        0 1px 2px rgba(27, 48, 35, 0.04),
        0 10px 28px rgba(27, 48, 35, 0.07);
    --shadow-pop: 0 18px 44px rgba(27, 48, 35, 0.16);
    --serif: "Playfair Display", Georgia, "Times New Roman", serif;
    --sans: "Inter", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 12% 4%, color-mix(in oklab, var(--accent-warm) 24%, transparent) 0%, transparent 34%),
        radial-gradient(circle at 88% 10%, color-mix(in oklab, var(--accent) 18%, transparent) 0%, transparent 40%),
        var(--background);
    color: var(--foreground);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
    font-family: var(--serif);
    font-weight: 500;
    line-height: 1.15;
    margin: 0;
    color: var(--primary);
}

.muted {
    color: var(--muted);
    font-size: 0.95rem;
}

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

/* ---------- Značka ---------- */

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.brand-large {
    flex-direction: column;
    gap: 0.5rem;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.85rem;
    background: color-mix(in oklab, var(--primary) 12%, var(--background-soft));
    color: var(--primary);
    border: 1px solid color-mix(in oklab, var(--primary) 22%, var(--border));
}

.brand-mark svg {
    width: 1.6rem;
    height: 1.6rem;
}

.brand-large .brand-mark {
    width: 3.4rem;
    height: 3.4rem;
}

.brand-large .brand-mark svg {
    width: 2rem;
    height: 2rem;
}

.brand-name {
    font-family: var(--serif);
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 0.01em;
}

.brand-sub {
    font-family: var(--sans);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0;
}

/* ---------- Hlášení ---------- */

.notice {
    position: fixed;
    top: 1.1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    max-width: min(92vw, 32rem);
    padding: 0.85rem 1.15rem;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-weight: 500;
    box-shadow: var(--shadow-pop);
    border: 1px solid transparent;
}

.notice.is-success {
    background: var(--ok-bg);
    color: var(--ok);
    border-color: color-mix(in oklab, var(--ok) 30%, var(--border));
}

.notice.is-error {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: color-mix(in oklab, var(--danger) 28%, var(--border));
}

/* ---------- Tlačítka a formulářové prvky ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.3rem;
    border-radius: 9999px;
    border: 1px solid transparent;
    font-family: var(--sans);
    font-size: 0.98rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform 160ms ease, background-color 160ms ease, opacity 160ms ease, box-shadow 160ms ease;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: var(--background-soft);
    box-shadow: 0 8px 20px color-mix(in oklab, var(--primary) 22%, transparent);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-press);
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-outline {
    background: transparent;
    border-color: color-mix(in oklab, var(--primary) 40%, var(--border));
    color: var(--primary);
}

.btn-outline:hover:not(:disabled) {
    background: color-mix(in oklab, var(--primary) 8%, transparent);
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--primary);
}

.btn-block {
    width: 100%;
}

.btn-lg {
    padding: 0.95rem 2rem;
    font-size: 1.05rem;
}

.field {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.field-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: color-mix(in oklab, var(--foreground) 76%, var(--primary));
    margin-bottom: 0.45rem;
}

.field-hint {
    display: block;
    margin-top: 0.45rem;
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.5;
}

input[type="text"],
input[type="password"],
select,
textarea {
    width: 100%;
    font-family: var(--sans);
    font-size: 0.98rem;
    color: var(--foreground);
    background: var(--background-soft);
    border: 1px solid color-mix(in oklab, var(--primary) 20%, var(--border));
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.85rem;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea {
    resize: vertical;
    min-height: 16rem;
    font-family: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    tab-size: 4;
}

/* ---------- WYSIWYG dokument (píše se přímo do panelu jako na webu) ---------- */

.doc-editor {
    display: grid;
    gap: 1rem;
    padding: 1.6rem 1.75rem 1.75rem;
    background: color-mix(in oklab, var(--primary) 5%, #ffffff);
    border: 2px solid color-mix(in oklab, var(--primary) 55%, var(--border));
    border-radius: var(--radius-lg);
    box-shadow:
        0 1px 2px color-mix(in oklab, var(--foreground) 5%, transparent),
        0 16px 40px color-mix(in oklab, var(--foreground) 9%, transparent);
    transition: border-color 160ms ease, box-shadow 160ms ease;
    position: relative;
}

/* Jemný štítek „dokument" v rohu, aby bylo jasné, že jde o editovatelný panel */
.doc-editor::before {
    content: "Dokument";
    position: absolute;
    top: -0.72rem;
    left: 1.35rem;
    padding: 0.15rem 0.7rem;
    border-radius: 9999px;
    background: var(--primary);
    color: var(--background-soft);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.doc-editor:focus-within {
    border-color: var(--primary);
    box-shadow:
        0 0 0 4px color-mix(in oklab, var(--primary) 16%, transparent),
        0 16px 40px color-mix(in oklab, var(--foreground) 9%, transparent);
}

.doc-editor.is-inactive {
    opacity: 0.62;
}

/* Indikace načítání obsahu z API */
.doc-editor:not([data-loaded]) {
    border-style: dashed;
}

.doc-editor[data-loaded="true"]::before {
    background: var(--primary);
}

.doc-editor:not([data-loaded])::before {
    content: "Načítám…";
    background: var(--muted);
}

/* Podnadpis – píše se přímo, vypadá jako na webu */
.doc-editor .updates-subtitle {
    margin: 0;
    padding: 0.45rem 0.6rem;
    border-radius: 0.4rem;
    border: 1px dashed transparent;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: center;
    outline: none;
    cursor: text;
    transition: background-color 140ms ease, border-color 140ms ease;
}

/* Obsah – stejné měřítko jako reálný panel */
.doc-editor .updates-text {
    display: grid;
    gap: 1rem;
    padding: 0.75rem 0.6rem;
    border: 1px dashed transparent;
    border-radius: 0.6rem;
    color: color-mix(in oklab, var(--foreground) 86%, transparent);
    font-size: 0.95rem;
    line-height: 1.55;
    outline: none;
    cursor: text;
    transition: background-color 140ms ease, border-color 140ms ease;
    min-height: 14rem;
}

.doc-editor .updates-subtitle:hover,
.doc-editor .updates-text:hover {
    background: color-mix(in oklab, var(--primary) 6%, transparent);
    border-color: color-mix(in oklab, var(--primary) 25%, transparent);
}

.doc-editor .updates-subtitle:focus,
.doc-editor .updates-text:focus {
    background: color-mix(in oklab, var(--primary) 8%, transparent);
    border-color: color-mix(in oklab, var(--primary) 45%, transparent);
}

.doc-editor .updates-subtitle:empty::before,
.doc-editor .updates-text:empty::before {
    content: attr(data-placeholder);
    color: color-mix(in oklab, var(--muted) 70%, transparent);
    font-weight: 400;
    letter-spacing: normal;
    text-transform: none;
    pointer-events: none;
}

.doc-editor h3 {
    color: var(--primary);
    font-family: var(--serif);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.2;
    margin: 0;
}

.doc-editor h3:not(:first-child) {
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid color-mix(in oklab, var(--border) 50%, transparent);
}

.doc-editor h4 {
    margin: 0.25rem 0 0;
    color: color-mix(in oklab, var(--foreground) 88%, var(--primary));
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.doc-editor ul,
.doc-editor ol {
    display: grid;
    gap: 0.35rem;
    margin: 0;
    padding-left: 1.1rem;
}

.doc-editor ul {
    list-style: disc;
}

.doc-editor ol {
    list-style: decimal;
    gap: 0.7rem;
    padding-left: 1.3rem;
}

.doc-editor li::marker {
    color: var(--primary);
    font-weight: 700;
}

.doc-editor p {
    margin: 0;
}

/* Ochranné pravidlo: blokové prvky nikdy nesmí být vnořené v odstavci.
   Když to prohlížeč udělá, rozbijeme vnoření a zrušíme odsazení navíc. */
.doc-editor p > ul,
.doc-editor p > ol,
.doc-editor p > h3,
.doc-editor p > h4,
.doc-editor p > p {
    margin-left: 0;
    padding-left: 0;
}

.doc-editor p:empty,
.doc-editor div:empty {
    display: none;
}

.doc-editor > * {
    margin-left: 0;
    margin-right: 0;
}

.doc-editor strong {
    font-weight: 700;
}

.doc-editor em {
    font-style: italic;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.switch input:focus-visible + .switch-track {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 18%, transparent);
}

/* ---------- Karty ---------- */

.card {
    background: color-mix(in oklab, var(--background-soft) 72%, var(--card));
    border: 1px solid color-mix(in oklab, var(--primary) 16%, var(--border));
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 1.25rem 1.35rem;
    margin-bottom: 1.1rem;
}

.card-header-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.4rem 1rem;
}

.card-header-row .field-hint {
    margin-top: 0;
}

.switch-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
}

.switch-copy {
    display: grid;
    gap: 0.2rem;
}

.switch-copy .field-label {
    margin-bottom: 0;
}

/* ---------- Přepínač ---------- */

.switch {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.switch-track {
    position: relative;
    width: 3.4rem;
    height: 1.9rem;
    border-radius: 9999px;
    background: color-mix(in oklab, var(--muted) 45%, var(--background));
    border: 1px solid color-mix(in oklab, var(--primary) 22%, var(--border));
    transition: background-color 180ms ease;
}

.switch-thumb {
    position: absolute;
    top: 0.2rem;
    left: 0.22rem;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    background: var(--background-soft);
    box-shadow: 0 2px 5px rgba(27, 48, 35, 0.25);
    transition: transform 180ms ease;
}

.switch input:checked + .switch-track {
    background: var(--primary);
    border-color: var(--primary);
}

.switch input:checked + .switch-track .switch-thumb {
    transform: translateX(1.45rem);
}

/* ---------- Rychlé vkládání a formátovací lišta ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
    padding: 0.5rem;
    background: color-mix(in oklab, var(--primary) 4%, var(--background-soft));
    border: 1px solid color-mix(in oklab, var(--primary) 14%, var(--border));
    border-radius: var(--radius-sm);
}

.toolbar-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
}

.toolbar-sep {
    width: 1px;
    align-self: stretch;
    margin: 0 0.3rem;
    background: color-mix(in oklab, var(--primary) 18%, var(--border));
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-width: 2.1rem;
    height: 2.1rem;
    padding: 0 0.55rem;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    background: transparent;
    color: color-mix(in oklab, var(--foreground) 80%, var(--primary));
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.tool-btn svg {
    width: 1.05rem;
    height: 1.05rem;
}

.tool-btn:hover {
    background: color-mix(in oklab, var(--primary) 10%, var(--background-soft));
    color: var(--primary);
}

.tool-btn:active {
    transform: scale(0.95);
}

.toolbar-status {
    margin-left: auto;
    padding: 0.2rem 0.65rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: var(--ok-bg);
    color: var(--ok);
    border: 1px solid color-mix(in oklab, var(--ok) 28%, var(--border));
}

.toolbar-status.is-off {
    background: color-mix(in oklab, var(--muted) 14%, var(--background-soft));
    color: var(--muted);
    border-color: color-mix(in oklab, var(--muted) 28%, var(--border));
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 0.42rem 0.85rem;
    border-radius: 9999px;
    border: 1px solid color-mix(in oklab, var(--primary) 28%, var(--border));
    background: color-mix(in oklab, var(--primary) 6%, var(--background-soft));
    color: var(--primary);
    font-family: var(--sans);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 150ms ease, transform 150ms ease;
}

.chip:hover {
    background: color-mix(in oklab, var(--primary) 13%, var(--background-soft));
    transform: translateY(-1px);
}

.clinic-insert {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.clinic-insert select {
    width: auto;
    padding: 0.42rem 0.6rem;
    font-size: 0.84rem;
    border-radius: 9999px;
}

/* ---------- Uložení ---------- */

.save-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.9rem 0 0.3rem;
    background: linear-gradient(180deg, transparent, var(--background) 55%);
}

.save-status {
    font-size: 0.88rem;
    color: var(--muted);
}

.save-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

#revert-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

#revert-btn:not(:disabled) {
    border-color: color-mix(in oklab, var(--primary) 45%, var(--border));
}

.save-status.is-ok {
    color: var(--ok);
    font-weight: 600;
}

.save-status.is-error {
    color: var(--danger);
    font-weight: 600;
}

/* ==========================================================================
   Přihlášení
   ========================================================================== */

.login-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1.15rem;
}

.login-card {
    width: min(100%, 26rem);
    text-align: left;
    padding: 2rem 1.9rem 1.6rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

.login-card .brand-large {
    align-items: flex-start;
    margin-bottom: 1.3rem;
}

.login-title {
    font-size: 1.75rem;
    margin-bottom: 0.4rem;
}

.login-card .muted {
    margin: 0 0 1.4rem;
}

.login-footer {
    margin: 1rem 0 0;
    font-size: 0.78rem;
    text-align: center;
}

/* ==========================================================================
   Editor
   ========================================================================== */

.admin-view[hidden],
.login-view[hidden],
.notice[hidden] {
    display: none;
}

.admin-header {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    max-width: 84rem;
    margin: 0 auto;
    padding: 0.9rem 1.4rem;
    background: color-mix(in oklab, var(--background-soft) 88%, var(--background));
    border-bottom: 1px solid color-mix(in oklab, var(--primary) 16%, var(--border));
    backdrop-filter: blur(8px);
}

.admin-header-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.admin-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
    max-width: 46rem;
    margin: 0 auto;
    padding: 1.5rem 1.4rem 0.5rem;
}

.admin-footer {
    max-width: 84rem;
    margin: 0 auto;
    padding: 1.4rem;
    font-size: 0.78rem;
    color: var(--muted);
    text-align: center;
}

/* Věrná replika komponenty .updates-disclosure z webu */

.updates-disclosure {
    border: 1px solid color-mix(in oklab, var(--primary) 58%, var(--border));
    border-radius: 1.25rem;
    background: color-mix(in oklab, var(--primary) 5%, var(--background-soft));
    box-shadow: 0 10px 30px color-mix(in oklab, var(--foreground) 4%, transparent);
    overflow: hidden;
    width: 100%;
}

.updates-disclosure[open] {
    box-shadow: 0 14px 36px color-mix(in oklab, var(--foreground) 7%, transparent);
}

.updates-disclosure summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.05rem 1.35rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
    font-weight: 600;
    color: color-mix(in oklab, var(--foreground) 78%, var(--primary));
}

.updates-disclosure summary::-webkit-details-marker {
    display: none;
}

.updates-disclosure summary:hover {
    background: color-mix(in oklab, var(--primary) 8%, transparent);
}

.holiday-alert-title-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.holiday-alert-icon,
.holiday-chevron {
    flex: 0 0 auto;
    color: color-mix(in oklab, var(--primary) 72%, var(--accent));
}

.holiday-chevron {
    transition: transform 200ms ease;
}

.updates-disclosure[open] .holiday-chevron {
    transform: rotate(180deg);
}

.updates-disclosure-content {
    display: grid;
    gap: 1rem;
    padding: 0 1.35rem 1.35rem;
    border-top: 1px solid color-mix(in oklab, var(--primary) 20%, var(--border));
}

.updates-subtitle {
    margin-top: 1rem;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: center;
}

.updates-text {
    display: grid;
    gap: 1rem;
    color: color-mix(in oklab, var(--foreground) 86%, transparent);
    font-size: 0.95rem;
    line-height: 1.55;
}

.updates-text h3 {
    color: var(--primary);
    font-family: var(--serif);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.2;
    margin: 0;
}

.updates-text h3:not(:first-child) {
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid color-mix(in oklab, var(--border) 50%, transparent);
}

.updates-text h4 {
    margin: 0.25rem 0 0;
    color: color-mix(in oklab, var(--foreground) 88%, var(--primary));
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.updates-text ul,
.updates-text ol {
    display: grid;
    gap: 0.35rem;
    padding-left: 1.1rem;
    margin: 0;
}

.updates-text ul {
    list-style: disc;
}

.updates-text ol {
    list-style: decimal;
    gap: 0.7rem;
    padding-left: 1.3rem;
}

.updates-text li::marker {
    color: var(--primary);
    font-weight: 700;
}

.updates-text p {
    margin: 0;
}

.updates-disclosure.is-inactive .updates-subtitle {
    opacity: 0.55;
}

/* ==========================================================================
   Responzivita
   ========================================================================== */

@media (max-width: 620px) {
    body {
        font-size: 15px;
    }

    .admin-header {
        padding: 0.75rem 1rem;
    }

    .admin-layout {
        padding: 1.1rem 1rem 0.4rem;
    }

    .card {
        padding: 1.05rem 1rem;
    }

    .doc-editor {
        padding: 1.05rem 1rem;
    }

    .toolbar-status {
        margin-left: 0;
        width: 100%;
        text-align: center;
    }

    .switch-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .brand-sub {
        display: none;
    }

    .save-bar {
        justify-content: stretch;
    }

    .save-actions {
        width: 100%;
        flex-direction: column-reverse;
    }

    .save-actions .btn {
        width: 100%;
    }
}

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