:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #18212f;
    --muted: #637083;
    --line: #dce3ea;
    --accent: #0f8f7f;
    --accent-dark: #0a6c61;
    --danger: #b3261e;
    --shadow: 0 18px 40px rgba(24, 33, 47, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.lucide-icon {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.lucide-icon svg {
    display: block;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.login-screen {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel {
    width: min(100%, 380px);
    padding: 32px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
}

.login-panel h1 {
    margin: 20px 0 28px;
    font-size: 30px;
}

.login-form {
    display: grid;
    gap: 12px;
}

.login-form label {
    color: var(--muted);
    font-weight: 650;
}

.login-form input {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-form button,
.ghost-button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.login-form button {
    background: var(--accent);
    color: #fff;
    font-weight: 750;
}

.login-form button:hover {
    background: var(--accent-dark);
}

.form-error {
    margin: 0;
    color: var(--danger);
}

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 24px;
    background: #102027;
    color: #fff;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    font-size: 20px;
}

.sidebar nav {
    display: grid;
    gap: 8px;
}

.sidebar-bottom {
    display: grid;
    margin-top: auto;
}

.nav-link {
    width: 100%;
    border: 0;
    padding: 12px;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.76);
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    justify-content: flex-start;
}

.nav-link.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.ghost-button {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    justify-content: flex-start;
}

.workspace {
    padding: 36px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 0;
    font-size: 34px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.panel {
    padding: 20px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(24, 33, 47, 0.06);
}

.panel h2 {
    margin: 0 0 16px;
    font-size: 20px;
}

.toolbar,
.pagination {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar {
    margin-bottom: 16px;
    align-items: flex-end;
}

.toolbar input {
    width: 100%;
}

.pagination {
    justify-content: flex-end;
    margin-top: 18px;
}

.list {
    display: grid;
    gap: 10px;
}

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.row-main {
    display: grid;
    gap: 4px;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.row-main:hover strong {
    color: var(--accent-dark);
}

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.list-row strong,
.list-row span {
    display: block;
}

.list-row span,
.empty-state {
    color: var(--muted);
}

.list-row p {
    margin: 8px 0 0;
}

.form-grid,
.settings-form {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
}

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

.form-grid .wide-field,
.form-grid fieldset,
.form-grid .form-error {
    grid-column: 1 / -1;
}

.field,
.radio-field {
    display: grid;
    gap: 6px;
}

.compact-field {
    min-width: 180px;
}

.field > span,
.radio-field legend,
.settings-form label > span {
    color: var(--muted);
    font-weight: 700;
}

.radio-field {
    margin: 0;
    padding: 0;
    border: 0;
    display: flex;
    align-items: center;
    align-content: start;
    flex-wrap: wrap;
    column-gap: 16px;
    row-gap: 6px;
}

.radio-field legend {
    width: 100%;
}

.radio-field label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-right: 0;
}

.radio-field input {
    width: auto;
}

.settings-form {
    max-width: 520px;
}

.settings-form label {
    display: grid;
    gap: 6px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    background: #fff;
    color: var(--text);
}

textarea {
    min-height: 88px;
    resize: vertical;
}

.large-note {
    min-height: 150px;
}

.primary-button,
.secondary-button,
.danger-button,
.pagination button,
.week-nav-button,
.tabs button {
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    padding: 0 14px;
    cursor: pointer;
    font-weight: 700;
}

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

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

.danger-button {
    background: #fde8e7;
    color: var(--danger);
}

.secondary-button,
.pagination button,
.week-nav-button,
.tabs button {
    background: #e8eef3;
    color: var(--text);
}

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

.list-row .danger-button,
.list-row .danger-button span {
    color: var(--danger);
}

.settings-form button.primary-button {
    color: #fff;
}

button span {
    color: inherit;
}

button:disabled {
    cursor: default;
    opacity: 0.5;
}

.side-drawer {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 10;
    display: grid;
    grid-template-rows: auto 1fr;
    width: min(100%, 520px);
    background: var(--panel);
    border-left: 1px solid var(--line);
    box-shadow: -18px 0 42px rgba(24, 33, 47, 0.18);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px;
    border-bottom: 1px solid var(--line);
}

.drawer-header h2 {
    margin: 0;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 8px;
    background: #e8eef3;
    color: var(--text);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.icon-only {
    padding: 0;
}

.drawer-content {
    min-height: 0;
    overflow: auto;
    padding: 20px;
}

.drawer-form,
.drawer-section {
    display: grid;
    gap: 14px;
}

.drawer-section {
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.drawer-section:last-child {
    border-bottom: 0;
}

.drawer-section h3 {
    margin: 0;
    font-size: 17px;
}

.button-row,
.form-actions,
.inline-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.form-actions {
    justify-content: flex-start;
}

.selected-patient {
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #effaf8;
    color: var(--accent-dark);
    font-weight: 700;
}

.picker-list {
    display: grid;
    gap: 8px;
}

.picker-row {
    display: grid;
    gap: 4px;
    width: 100%;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.picker-row:hover {
    border-color: var(--accent);
}

.picker-row span {
    color: var(--muted);
}

.calendar-week-header {
    display: flex;
    justify-content: center;
    margin-bottom: 18px;
}

.week-control {
    display: grid;
    grid-template-columns: 44px minmax(0, auto) 44px;
    align-items: start;
    gap: 8px;
}

.week-title-wrap {
    display: grid;
    justify-items: center;
    gap: 8px;
    position: relative;
}

.week-title-button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 0 18px;
    background: #effaf8;
    color: var(--accent-dark);
    cursor: pointer;
    font-size: 20px;
    font-weight: 600;
}

.week-date-picker {
    position: absolute;
    top: 100%;
    left: 50%;
    z-index: 2;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0.01;
    transform: translateX(-50%);
}

.calendar-days,
.letter-list {
    display: grid;
    gap: 18px;
}

.calendar-day h2,
.letter-group h2 {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 15px;
    text-transform: lowercase;
}

.letter-group h2 {
    text-transform: uppercase;
}

.appointment-row {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.appointment-row time {
    color: var(--accent-dark);
    font-size: 20px;
    font-weight: 600;
}

.appointment-main {
    min-width: 0;
}

.appointment-patient-link,
.appointment-main span {
    display: block;
}

.appointment-patient-link {
    justify-content: flex-start;
    width: fit-content;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
}

.appointment-patient-link:hover {
    color: var(--accent-dark);
}

.appointment-main span,
.appointment-main p {
    color: var(--muted);
}

.appointment-main p {
    margin: 6px 0 0;
    overflow-wrap: anywhere;
}

@media (hover: hover) and (pointer: fine) {
    .hover-actions {
        opacity: 0;
        pointer-events: none;
        transition: opacity 140ms ease;
    }

    .appointment-row:hover .hover-actions,
    .list-row:hover .hover-actions,
    .visit-card:hover .hover-actions {
        opacity: 1;
        pointer-events: auto;
    }
}

.patient-layout {
    display: grid;
    gap: 18px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.section-header h2 {
    margin: 0;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin: 0;
}

.details-grid div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.details-grid dt {
    margin-bottom: 6px;
    color: var(--muted);
    font-weight: 700;
}

.details-grid dd {
    margin: 0;
}

.details-grid .wide-field {
    grid-column: 1 / -1;
}

.patient-edit-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.patient-edit-grid .wide-field,
.patient-edit-grid .form-error {
    grid-column: 1 / -1;
}

.patient-edit-grid > .field:nth-child(2) {
    grid-column: span 2;
}

.bmi-chart {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.bmi-chart-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.bmi-chart-header h3 {
    margin: 0;
    font-size: 16px;
}

.bmi-chart-header span {
    color: var(--accent-dark);
    font-weight: 700;
}

.bmi-chart svg {
    display: block;
    width: 100%;
    height: auto;
    min-height: 170px;
    overflow: visible;
}

.bmi-chart-grid line {
    stroke: var(--line);
    stroke-width: 1;
}

.bmi-chart-grid text,
.bmi-chart-date {
    fill: var(--muted);
    font-size: 12px;
}

.bmi-chart-grid text {
    text-anchor: end;
}

.bmi-chart-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.bmi-chart-point circle {
    fill: var(--panel);
    stroke: var(--accent-dark);
    stroke-width: 2;
}

.visit-list {
    display: grid;
    gap: 12px;
}

.visit-card {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.visit-card.editing {
    margin-block: 24px;
    background: #fff;
}

.visit-table {
    display: grid;
    grid-template-columns: 100px 70px 80px 80px 70px 80px 80px 120px minmax(220px, 1fr);
    gap: 10px;
    align-items: start;
}

.visit-table div {
    min-width: 0;
}

.visit-table span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.visit-table p {
    display: block;
    margin: 0;
    overflow-wrap: anywhere;
}

.visit-edit-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.visit-edit-form .wide-field,
.visit-edit-form .form-error {
    grid-column: 1 / -1;
}

.visit-edit-form .form-actions,
.visit-edit-form .calculation-preview {
    grid-column: 1 / -1;
}

.calculation-preview {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.calculation-preview div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #effaf8;
}

.calculation-preview span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.calculation-preview strong {
    color: var(--accent-dark);
    font-size: 20px;
}

.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--line);
}

.tabs button {
    border-radius: 8px 8px 0 0;
    border: 1px solid transparent;
    border-bottom: 0;
    background: transparent;
    color: var(--muted);
}

.tabs button.active {
    position: relative;
    top: 1px;
    background: var(--panel);
    border-color: var(--line);
    color: var(--accent-dark);
}

@media (max-width: 760px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: auto;
    }

    .workspace {
        padding: 24px;
    }

    .page-header {
        display: grid;
    }

    .page-header h1 {
        font-size: 30px;
    }

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

    .list-row {
        align-items: stretch;
    }

    .row-actions {
        justify-content: flex-start;
    }

    .pagination {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .details-grid,
    .patient-edit-grid,
    .visit-edit-form,
    .calculation-preview {
        grid-template-columns: 1fr;
    }

    .patient-edit-grid > .field:nth-child(2) {
        grid-column: auto;
    }

    .visit-table {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .visit-note {
        grid-column: 1 / -1;
    }

    .appointment-row {
        grid-template-columns: 64px minmax(0, 1fr);
    }

    .appointment-row .row-actions {
        grid-column: 1 / -1;
    }

    .week-control {
        grid-template-columns: 42px minmax(0, 1fr) 42px;
        width: 100%;
    }

    .button-row,
    .form-actions,
    .inline-actions,
    .tabs {
        align-items: stretch;
    }
}
