/* KlinikMS — clean medical/business theme.
   White and light, no animation, no dark mode. */

:root {
    --km-primary: #16697a;
    --km-primary-dark: #10505e;
    --km-primary-soft: #e6f1f3;
    --km-accent: #2a9d8f;
    --km-border: #e2e8ec;
    --km-ink: #1f2d33;
    --km-muted: #6b7b83;
    --km-bg: #f5f7f8;
    --km-danger: #b3261e;
    --km-warn: #a16207;
    --km-sidebar-w: 240px;
}

* {
    box-shadow: none !important;
}

html, body {
    height: 100%;
}

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

a {
    color: var(--km-primary);
    text-decoration: none;
}

a:hover {
    color: var(--km-primary-dark);
    text-decoration: underline;
}

/* ---------- shell ---------- */

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

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-content {
    flex: 1 1 auto;
    padding: 1.25rem 1.5rem 2rem;
}

.app-footer {
    border-top: 1px solid var(--km-border);
    padding: 0.75rem 1.5rem;
    color: var(--km-muted);
    font-size: 0.8rem;
    background: #fff;
}

/* ---------- sidebar ---------- */

.app-sidebar {
    width: var(--km-sidebar-w);
    flex: 0 0 var(--km-sidebar-w);
    background: #fff;
    border-right: 1px solid var(--km-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 1rem 0.9rem;
    border-bottom: 1px solid var(--km-border);
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--km-ink);
    font-weight: 700;
    letter-spacing: 0.01em;
}

.brand-link:hover {
    text-decoration: none;
    color: var(--km-primary);
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--km-primary);
    color: #fff;
    font-weight: 700;
}

.sidebar-nav {
    padding: 0.75rem 0.6rem;
    overflow-y: auto;
    flex: 1 1 auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    color: var(--km-ink);
    font-weight: 500;
}

.nav-item:hover {
    background: var(--km-primary-soft);
    color: var(--km-primary-dark);
    text-decoration: none;
}

.nav-item.active {
    background: var(--km-primary);
    color: #fff;
}

.nav-ico {
    width: 1.1rem;
    text-align: center;
    opacity: 0.9;
}

.nav-sep {
    height: 1px;
    background: var(--km-border);
    margin: 0.6rem 0.4rem;
}

.sidebar-foot {
    border-top: 1px solid var(--km-border);
    padding: 0.85rem 1rem 1rem;
}

.sidebar-backdrop {
    display: none;
}

/* ---------- topbar ---------- */

.app-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #fff;
    border-bottom: 1px solid var(--km-border);
    padding: 0.7rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.topbar-right {
    margin-left: auto;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--km-primary-soft);
    color: var(--km-primary-dark);
    font-weight: 600;
    font-size: 0.85rem;
}

/* ---------- cards & panels ---------- */

.card, .panel {
    background: #fff;
    border: 1px solid var(--km-border);
    border-radius: 10px;
}

.panel-head {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--km-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.panel-head h2, .panel-head h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.panel-body {
    padding: 1rem;
}

.page-head {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.page-head h2 {
    font-size: 1.35rem;
    font-weight: 600;
    margin: 0 0 0.15rem;
}

.page-head .sub {
    color: var(--km-muted);
    font-size: 0.9rem;
}

.page-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ---------- stat tiles ---------- */

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

.stat {
    background: #fff;
    border: 1px solid var(--km-border);
    border-radius: 10px;
    padding: 1rem;
}

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

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--km-primary-dark);
    line-height: 1.2;
    margin-top: 0.25rem;
}

.stat-hint {
    color: var(--km-muted);
    font-size: 0.82rem;
}

/* ---------- dashboard home ---------- */

.dashboard-welcome {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    min-height: 230px;
    padding: 1.25rem 1.4rem 1rem 1.65rem;
    border: 1px solid #dce9e9;
    border-radius: 14px;
    background: linear-gradient(115deg, #fff 0%, #f2f8f7 100%);
    overflow: hidden;
}

.dashboard-welcome-copy { position: relative; z-index: 1; flex: 1 1 450px; }
.dashboard-illustration { display: block; width: min(42%, 420px); max-height: 220px; align-self: stretch; object-fit: cover; object-position: center 48%; border-radius: 10px; mix-blend-mode: multiply; }

.dashboard-eyebrow {
    color: var(--km-primary);
    font-size: 0.7rem;
    font-weight: 750;
    letter-spacing: 0.12em;
}

.dashboard-live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin: 0 0.3rem 1px 0;
    border-radius: 50%;
    background: var(--km-accent);
}

.dashboard-welcome h2 {
    margin: 0.45rem 0 0.25rem;
    color: #173c43;
    font-size: clamp(1.65rem, 3vw, 2.15rem);
    font-weight: 750;
    letter-spacing: -0.04em;
}

.dashboard-welcome p {
    margin: 0;
    color: var(--km-muted);
}

.dashboard-welcome-actions {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.dashboard-date {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.48rem 0.75rem;
    border: 1px solid var(--km-border);
    border-radius: 8px;
    background: #fff;
    color: var(--km-muted);
    font-size: 0.85rem;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.65rem;
}

.dashboard-stat {
    display: block;
    min-width: 0;
    padding: 1rem 1.1rem;
    border: 1px solid var(--km-border);
    border-radius: 11px;
    background: #fff;
    color: inherit;
    transition: border-color 120ms ease, transform 120ms ease;
}

.dashboard-stat:hover {
    border-color: #b7d2d4;
    color: inherit;
    text-decoration: none;
    transform: translateY(-1px);
}

.dashboard-stat-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.dashboard-stat-label {
    color: var(--km-muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.035em;
    text-transform: uppercase;
}

.dashboard-stat-icon {
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    border-radius: 9px;
    background: var(--km-primary-soft);
    color: var(--km-primary);
    font-size: 1rem;
    font-weight: 700;
}

.stat-visits .dashboard-stat-icon { background: #e8f4ef; color: #287657; }
.stat-revenue .dashboard-stat-icon { background: #f1edfa; color: #66509a; font-size: 0.75rem; }
.stat-appointments .dashboard-stat-icon { background: #fff4e6; color: #a16207; }

.dashboard-stat-value {
    margin-top: 0.65rem;
    color: #173c43;
    font-size: 2rem;
    font-weight: 750;
    letter-spacing: -0.045em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.dashboard-stat-money { font-size: clamp(1.2rem, 2vw, 1.65rem); }

.dashboard-stat-hint {
    margin-top: 0.35rem;
    color: var(--km-muted);
    font-size: 0.8rem;
}

.dashboard-section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.8rem;
}

.dashboard-section-heading h3 {
    margin: 0.2rem 0 0;
    color: var(--km-ink);
    font-size: 1.15rem;
    font-weight: 700;
}

.dashboard-section-heading > a,
.dashboard-panel .panel-head > a {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.dashboard-panel { overflow: hidden; border-radius: 11px; }
.dashboard-panel .panel-head { min-height: 68px; justify-content: space-between; }
.dashboard-panel-sub { margin-top: 0.2rem; color: var(--km-muted); font-size: 0.8rem; }
.dashboard-panel-count {
    display: inline-flex;
    min-width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    padding: 0 0.45rem;
    border-radius: 999px;
    background: var(--km-primary-soft);
    color: var(--km-primary-dark);
    font-size: 0.8rem;
    font-weight: 700;
}

.dashboard-primary-link { font-weight: 600; }
.dashboard-time { color: var(--km-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

@media (max-width: 991.98px) {
    .dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 575.98px) {
    .dashboard-welcome { padding: 1.15rem; }
    .dashboard-welcome-copy { flex-basis: 100%; }
    .dashboard-illustration { width: 100%; max-height: 170px; object-position: center 42%; }
    .dashboard-welcome-actions { width: 100%; margin-top: 0.85rem; }
    .dashboard-date { width: 100%; }
    .dashboard-stats { gap: 0.6rem; }
    .dashboard-stat { padding: 0.85rem; }
    .dashboard-stat-label { font-size: 0.69rem; }
    .dashboard-stat-value { font-size: 1.7rem; }
    .dashboard-stat-money { font-size: 1.15rem; }
}

/* ---------- tables ---------- */

.table-wrap {
    overflow-x: auto;
}

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

table.km th {
    text-align: left;
    font-weight: 600;
    color: var(--km-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--km-border);
    background: #fafbfc;
    white-space: nowrap;
}

table.km td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--km-border);
    vertical-align: middle;
}

table.km tbody tr:hover {
    background: #fafcfc;
}

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

.empty-state {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--km-muted);
}

/* ---------- badges ---------- */

.badge-soft {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-soft.ok       { background: #e7f4ee; color: #14663f; border-color: #c6e6d6; }
.badge-soft.info     { background: #e7f0f7; color: #1d4e79; border-color: #cbdff0; }
.badge-soft.warn     { background: #fdf3e2; color: var(--km-warn); border-color: #f2e0bd; }
.badge-soft.danger   { background: #fbeae9; color: var(--km-danger); border-color: #f3cfcc; }
.badge-soft.muted    { background: #eef1f3; color: #54646c; border-color: #dee4e8; }

/* ---------- forms ---------- */

.form-label {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

.form-control, .form-select {
    border-color: var(--km-border);
    font-size: 0.92rem;
    padding: 0.45rem 0.65rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--km-primary);
    box-shadow: 0 0 0 3px var(--km-primary-soft) !important;
}

.required::after {
    content: " *";
    color: var(--km-danger);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--km-muted);
    margin-top: 0.2rem;
}

.field-error {
    font-size: 0.8rem;
    color: var(--km-danger);
    margin-top: 0.2rem;
}

.has-error .form-control, .has-error .form-select {
    border-color: var(--km-danger);
}

.form-section {
    border-top: 1px solid var(--km-border);
    margin-top: 1.25rem;
    padding-top: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    border-top: 1px solid var(--km-border);
    margin-top: 1.5rem;
    padding-top: 1rem;
}

/* ---------- buttons ---------- */

.btn-primary {
    background: var(--km-primary);
    border-color: var(--km-primary);
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--km-primary-dark);
    border-color: var(--km-primary-dark);
}

.btn-outline-primary {
    color: var(--km-primary);
    border-color: var(--km-primary);
}

.btn-outline-primary:hover {
    background: var(--km-primary);
    border-color: var(--km-primary);
}

/* ---------- filters & pagination ---------- */

.filter-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.pagination-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--km-border);
    color: var(--km-muted);
    font-size: 0.85rem;
}

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

.dl {
    display: grid;
    grid-template-columns: minmax(140px, 200px) 1fr;
    gap: 0.4rem 1rem;
    margin: 0;
    font-size: 0.92rem;
}

.dl dt {
    color: var(--km-muted);
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding-top: 0.15rem;
}

.dl dd {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- timeline ---------- */

.timeline {
    border-left: 2px solid var(--km-border);
    margin-left: 0.5rem;
    padding-left: 1rem;
}

.timeline-item {
    position: relative;
    padding-bottom: 1.1rem;
}

.timeline-item::before {
    content: "";
    position: absolute;
    left: -1.42rem;
    top: 0.35rem;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--km-primary);
}

.timeline-date {
    font-size: 0.8rem;
    color: var(--km-muted);
    font-weight: 600;
}

/* ---------- auth ---------- */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--km-bg);
}

/* Stacks the flash/error banner on top of the sign-in card. Without this the
   banner is a flex sibling of the card and pushes the card sideways, so the
   whole form jumps right whenever a login attempt fails. */
.auth-stack {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-stack > .alert {
    margin-bottom: 0;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border: 1px solid var(--km-border);
    border-radius: 12px;
    padding: 1.75rem;
}

.auth-brand {
    text-align: center;
    margin-bottom: 1.25rem;
}

.auth-brand .brand-mark {
    width: 44px;
    height: 44px;
    font-size: 1.3rem;
    margin: 0 auto 0.5rem;
}

.auth-brand h1 {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
}

.auth-brand p {
    color: var(--km-muted);
    font-size: 0.88rem;
    margin: 0.25rem 0 0;
}

.demo-box {
    margin-top: 1.25rem;
    font-size: 0.82rem;
    color: var(--km-muted);
}

.demo-box code {
    color: var(--km-ink);
}

.demo-account {
    padding: 0.3rem 0;
    line-height: 1.45;
    user-select: text;
}

.demo-account + .demo-account {
    border-top: 1px solid #edf1f4;
    padding-top: 0.45rem;
    margin-top: 0.15rem;
}

.demo-who {
    color: var(--km-ink);
    font-weight: 600;
}

.demo-credentials {
    display: block;
    overflow-wrap: anywhere;
}

.demo-sep {
    color: var(--km-muted);
}

/* ---------- invoice / prescription items editor ---------- */

.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--km-muted);
    font-weight: 600;
    padding: 0.35rem 0.4rem;
    text-align: left;
}

.items-table td {
    padding: 0.25rem 0.4rem;
    vertical-align: top;
}

.item-row-remove {
    color: var(--km-danger);
    background: none;
    border: 0;
    cursor: pointer;
    padding: 0.4rem;
    font-size: 1rem;
    line-height: 1;
}

/* ---------- alerts ---------- */

.alert {
    border-radius: 8px;
    font-size: 0.92rem;
}

/* ---------- print helpers ---------- */

.print-only {
    display: none;
}

/* ---------- responsive ---------- */

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1040;
        transform: translateX(-100%);
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 32, 38, 0.35);
        z-index: 1030;
    }

    .sidebar-backdrop.open {
        display: block;
    }

    .app-content {
        padding: 1rem;
    }

    .app-topbar {
        padding: 0.65rem 1rem;
    }

    .dl {
        grid-template-columns: 1fr;
        gap: 0.1rem;
    }

    .dl dt {
        padding-top: 0.5rem;
    }
}

@media (max-width: 575.98px) {
    .stat-value {
        font-size: 1.45rem;
    }

    .page-actions {
        width: 100%;
        margin-left: 0;
    }

    .page-actions .btn {
        flex: 1 1 auto;
    }
}
