:root {
    --ink: #17324d;
    --muted: #6c7d8f;
    --line: #dce6ed;
    --panel: #ffffff;
    --canvas: #f3f7f9;
    --primary: #146c78;
    --primary-dark: #0b5360;
    --primary-soft: #e1f2f2;
    --blue-soft: #e8f0ff;
    --warning-soft: #fff5dc;
    --danger: #c33c54;
    --shadow: 0 18px 50px rgba(25, 54, 75, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at top right, rgba(82, 184, 178, 0.12), transparent 28rem),
        var(--canvas);
    font-family: "Noto Sans Thai", system-ui, sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

.app-container {
    max-width: 1480px;
    padding-right: clamp(1rem, 3vw, 2.5rem);
    padding-left: clamp(1rem, 3vw, 2.5rem);
}

.app-header {
    position: sticky;
    z-index: 1020;
    top: 0;
    border-bottom: 1px solid rgba(220, 230, 237, 0.9);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
}

.app-header .app-container {
    display: flex;
    min-height: 76px;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand,
.header-actions,
.user-chip {
    display: flex;
    align-items: center;
}

.brand {
    gap: 0.85rem;
}

.brand-mark {
    display: grid;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    place-items: center;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(145deg, #1c8790, #0b5968);
    box-shadow: 0 10px 22px rgba(20, 108, 120, 0.24);
    font-size: 1.35rem;
    font-weight: 700;
}

.brand-title {
    margin: 0;
    font-size: clamp(1rem, 2vw, 1.2rem);
    font-weight: 700;
}

.eyebrow {
    margin: 0 0 0.3rem;
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
}

.header-actions {
    gap: 0.75rem;
}

.user-chip {
    gap: 0.45rem;
    padding: 0.55rem 0.8rem;
    border-radius: 999px;
    color: var(--muted);
    background: #f4f7f9;
    font-size: 0.9rem;
}

.hero-panel {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1.5rem;
    padding: clamp(1.2rem, 3vw, 2rem);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 24px;
    color: #fff;
    background:
        linear-gradient(115deg, rgba(7, 73, 83, 0.98), rgba(20, 108, 120, 0.9)),
        #0f6470;
    box-shadow: var(--shadow);
}

.hero-panel .eyebrow {
    color: #a9e2df;
}

.hero-panel h2 {
    margin: 0;
    font-size: clamp(1.55rem, 4vw, 2.4rem);
    font-weight: 700;
}

.hero-copy {
    margin: 0.45rem 0 0;
    color: rgba(255, 255, 255, 0.76);
}

.hero-panel .btn-primary {
    flex: 0 0 auto;
    border-color: #fff;
    color: var(--primary-dark);
    background: #fff;
}

.hero-panel .btn-primary:hover {
    border-color: #e6fbfa;
    background: #e6fbfa;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.stat-card {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
    box-shadow: 0 10px 30px rgba(25, 54, 75, 0.05);
}

.stat-icon {
    display: grid;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    place-items: center;
    border-radius: 15px;
    font-size: 1.25rem;
}

.stat-today .stat-icon {
    color: #0f766e;
    background: var(--primary-soft);
}

.stat-month .stat-icon {
    color: #315da8;
    background: var(--blue-soft);
}

.stat-upcoming .stat-icon {
    color: #9a6500;
    background: var(--warning-soft);
}

.stat-card p {
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.88rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-card strong {
    display: block;
    margin-top: 0.15rem;
    font-size: 1.75rem;
    line-height: 1;
}

.calendar-panel {
    padding: clamp(0.8rem, 2.5vw, 1.5rem);
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.fc {
    --fc-border-color: #e6edf2;
    --fc-button-bg-color: #146c78;
    --fc-button-border-color: #146c78;
    --fc-button-hover-bg-color: #0b5360;
    --fc-button-hover-border-color: #0b5360;
    --fc-button-active-bg-color: #084852;
    --fc-button-active-border-color: #084852;
    --fc-today-bg-color: rgba(20, 108, 120, 0.08);
    color: var(--ink);
}

.fc .fc-toolbar-title {
    font-size: clamp(1.05rem, 3vw, 1.5rem);
    font-weight: 700;
}

.fc .fc-button {
    border-radius: 10px;
    box-shadow: none !important;
    font-weight: 600;
}

.fc .fc-col-header-cell-cushion,
.fc .fc-daygrid-day-number {
    color: var(--ink);
    text-decoration: none;
}

.fc .fc-col-header-cell-cushion {
    padding: 0.65rem 0.25rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.fc .fc-daygrid-day-number {
    padding: 0.5rem;
    font-size: 0.88rem;
}

.fc .fc-daygrid-event {
    padding: 0.15rem 0.3rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.76rem;
}

.fc .fc-daygrid-day-frame {
    min-height: 102px;
}

.btn {
    border-radius: 11px;
    font-weight: 600;
}

.btn-primary {
    border-color: var(--primary);
    background-color: var(--primary);
}

.btn-primary:hover,
.btn-primary:focus {
    border-color: var(--primary-dark);
    background-color: var(--primary-dark);
}

.btn-outline-secondary {
    border-color: #cbd8e0;
    color: #4c6476;
}

.modal-content {
    overflow: hidden;
    border: 0;
    border-radius: 22px;
    box-shadow: 0 24px 80px rgba(24, 49, 68, 0.2);
}

.appointment-form {
    display: flex;
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    flex-direction: column;
}

.appointment-form .modal-header,
.appointment-form .modal-footer {
    flex: 0 0 auto;
}

.appointment-form .modal-body {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.modal-header,
.modal-footer {
    padding: 1.15rem 1.4rem;
    border-color: var(--line);
}

.modal-body {
    padding: 1.4rem;
}

.form-label {
    color: #344c5f;
    font-size: 0.9rem;
    font-weight: 600;
}

.form-control,
.form-select {
    min-height: 46px;
    border-color: #cfdae2;
    border-radius: 11px;
}

textarea.form-control {
    min-height: 96px;
}

.form-control:focus,
.form-select:focus {
    border-color: #48a8ac;
    box-shadow: 0 0 0 0.22rem rgba(20, 108, 120, 0.13);
}

.required {
    color: var(--danger);
}

.appointment-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.appointment-card {
    display: flex;
    min-width: 0;
    flex-direction: column;
    padding: 1.1rem;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(25, 54, 75, 0.06);
}

.appointment-card-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.9rem;
    border-bottom: 1px solid #edf1f4;
}

.appointment-card h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.hn-label {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.detail-pill {
    flex: 0 0 auto;
    padding: 0.3rem 0.55rem;
    border-radius: 999px;
    color: #2358a0;
    background: var(--blue-soft);
    font-size: 0.72rem;
    font-weight: 700;
}

.detail-pill.medicine {
    color: #0f6f69;
    background: var(--primary-soft);
}

.appointment-meta {
    display: grid;
    gap: 0.72rem;
    padding: 1rem 0;
}

.meta-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 0.55rem;
    align-items: start;
}

.meta-row > i {
    color: var(--primary);
}

.meta-row small {
    display: block;
    margin-bottom: 0.05rem;
    color: var(--muted);
    font-size: 0.72rem;
}

.meta-row span {
    display: block;
    color: #30495c;
    font-size: 0.87rem;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.appointment-actions {
    display: flex;
    gap: 0.55rem;
    margin-top: auto;
    padding-top: 0.9rem;
    border-top: 1px solid #edf1f4;
}

.appointment-actions .btn {
    flex: 1;
    font-size: 0.82rem;
}

.pagination-bar {
    justify-content: center;
}

.page-indicator {
    min-width: 100px;
    color: var(--muted);
    text-align: center;
    font-size: 0.9rem;
}

.empty-state {
    padding: 3rem 1rem;
    color: var(--muted);
    text-align: center;
}

.empty-state i {
    display: block;
    margin-bottom: 0.75rem;
    color: #9db0bd;
    font-size: 3rem;
}

.empty-state h3 {
    color: var(--ink);
    font-size: 1.1rem;
}

.toast {
    color: #fff;
    background: #173d47;
}

.toast.toast-error {
    background: #a52d43;
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 1rem;
    background:
        radial-gradient(circle at 10% 10%, rgba(82, 184, 178, 0.25), transparent 30rem),
        linear-gradient(145deg, #edf5f5, #f7f9fb);
}

.login-shell {
    width: min(100%, 450px);
}

.login-card {
    padding: clamp(1.5rem, 5vw, 2.5rem);
    border: 1px solid rgba(255, 255, 255, 0.85);
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 30px 90px rgba(25, 54, 75, 0.14);
}

.login-card .brand-mark {
    margin-bottom: 1.2rem;
}

.login-card h1 {
    margin: 0;
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 700;
}

@media (max-width: 991.98px) {
    .appointment-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 767.98px) {
    #appointmentFormModal .modal-dialog {
        margin: 0;
    }

    #appointmentFormModal .modal-content {
        min-height: 100vh;
        min-height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    #appointmentFormModal .modal-header,
    #appointmentFormModal .modal-body,
    #appointmentFormModal .modal-footer {
        padding-right: 1rem;
        padding-left: 1rem;
    }

    #appointmentFormModal .modal-footer {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        background: #fff;
    }

    #appointmentFormModal .modal-footer .btn {
        flex: 1;
    }

    .app-header .app-container {
        min-height: 66px;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
        border-radius: 12px;
    }

    .hero-panel {
        align-items: stretch;
        flex-direction: column;
    }

    .hero-panel .btn {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.7rem;
    }

    .stat-card {
        padding: 0.85rem 1rem;
    }

    .stat-icon {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
    }

    .stat-card strong {
        font-size: 1.4rem;
    }

    .appointment-grid {
        grid-template-columns: 1fr;
    }

    .fc .fc-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 0.65rem;
    }

    .fc .fc-toolbar-chunk {
        display: flex;
        justify-content: center;
    }

    .fc .fc-daygrid-day-frame {
        min-height: 76px;
    }

    .fc .fc-daygrid-event {
        padding: 0.1rem 0.2rem;
        font-size: 0.66rem;
    }

    .fc .fc-daygrid-day-number {
        padding: 0.3rem;
        font-size: 0.78rem;
    }
}

@media (max-width: 399.98px) {
    .brand .eyebrow {
        display: none;
    }

    .brand-title {
        font-size: 0.92rem;
    }

    .header-actions .btn {
        padding-right: 0.7rem;
        padding-left: 0.7rem;
    }
}
