* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
    background: #f3f4f6;
    color: #1f2937;
}

body.modal-open {
    overflow: hidden;
}

a {
    text-decoration: none;
}

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

select,
input,
textarea {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 9px 10px;
    font-size: 14px;
    background: #ffffff;
    color: #111827;
}

textarea {
    resize: vertical;
}

input[type="date"],
input[type="time"] {
    min-width: 135px;
}

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

.sidebar {
    width: 240px;
    background: #080d18;
    color: #ffffff;
    padding: 28px 20px;
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
}

.sidebar-close-btn,
.sidebar-open-btn {
    display: none;
}

.brand {
    margin-bottom: 28px;
}

.brand-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 1px;
}

.brand-sub {
    margin-top: 6px;
    color: #9ca3af;
    font-size: 13px;
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.nav-title {
    margin: 0 0 8px 4px;
    font-size: 12px;
    color: #9ca3af;
    font-weight: 800;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.side-nav a {
    color: #d1d5db;
    padding: 11px 13px;
    border-radius: 12px;
    transition: 0.15s;
}

.side-nav a:hover {
    background: #1f2937;
    color: #ffffff;
}

.side-nav a.logout {
    color: #fca5a5;
}

.main {
    flex: 1;
    margin-left: 240px;
    max-width: calc(100vw - 240px);
    min-height: 100vh;
    padding: 32px;
    background: #f3f4f6;
    overflow-x: hidden;
}

.page-head,
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.page-head {
    margin-bottom: 22px;
}

.card-head {
    margin-bottom: 18px;
}

.page-head h1 {
    margin: 0;
    color: #111827;
    font-size: 28px;
}

.page-head p,
.card-head p {
    margin: 8px 0 0;
    color: #6b7280;
    font-size: 14px;
}

.card-head h2 {
    margin: 0;
    font-size: 20px;
    color: #111827;
}

.card {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    background: #ffffff;
    border-radius: 18px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    margin-bottom: 22px;
}

.page-card {
    width: 100%;
}

.narrow-card {
    max-width: 900px;
}

.form-card,
.filter-card {
    max-width: 1200px;
}

.btn-primary,
.btn-secondary,
.btn-small {
    border: 0;
    cursor: pointer;
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 700;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.btn-primary {
    background: #0f172a;
    color: #ffffff;
}

.btn-primary:hover {
    background: #1e293b;
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}

.btn-secondary:hover {
    background: #d1d5db;
}

.btn-small {
    background: #1f2937;
    color: #ffffff;
    padding: 8px 10px;
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1000px;
    font-size: 14px;
}

.simple-table {
    min-width: 720px;
}

th {
    background: #111827;
    color: #ffffff;
    padding: 12px 10px;
    white-space: nowrap;
    border: 1px solid #374151;
}

td {
    padding: 11px 10px;
    border: 1px solid #e5e7eb;
    text-align: center;
    vertical-align: middle;
}

tbody tr:hover {
    background: #f9fafb;
}

.sort-link {
    color: #ffffff;
    text-decoration: none;
}

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

.strong {
    font-weight: 700;
    color: #111827;
}

.memo-cell {
    min-width: 220px;
    max-width: 320px;
    white-space: pre-wrap;
    text-align: left;
}

.count-cell {
    min-width: 180px;
    text-align: left;
    line-height: 1.6;
    font-size: 13px;
}

.empty {
    padding: 40px;
    color: #6b7280;
}

.empty-inline {
    color: #6b7280;
    font-size: 14px;
}

.icon-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
}

.icon-actions form {
    margin: 0;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    color: #111827;
    border-radius: 10px;
    cursor: pointer;
    font-size: 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.icon-btn:hover {
    background: #e5e7eb;
}

.icon-btn.danger {
    background: #fee2e2;
    border-color: #fecaca;
    color: #991b1b;
}

.icon-btn.danger:hover {
    background: #fecaca;
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}

.inline-form,
.search-form {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr auto;
    gap: 14px;
    align-items: end;
}

.search-form {
    grid-template-columns: 1fr 1fr 1fr auto;
}

.compact-search {
    grid-template-columns: 260px auto;
    margin-bottom: 18px;
}

.search-actions,
.form-actions {
    display: flex;
    gap: 10px;
}

.grid-form label,
.inline-form label,
.search-form label,
.modal-form label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-weight: 700;
    color: #374151;
}

.full {
    grid-column: 1 / -1;
}

.visit-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.visit-top {
    grid-template-columns: 1.5fr 1fr 1fr auto;
}

.treatment-form {
    grid-template-columns: 1fr auto;
}

.user-form {
    grid-template-columns: 1fr 1fr 1fr auto;
}

.checkbox-area {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 16px;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: center;
}

.label-title {
    font-weight: 800;
    margin-right: 8px;
}

.check-item {
    display: flex;
    gap: 6px;
    align-items: center;
    background: #ffffff;
    padding: 9px 12px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    cursor: pointer;
}

.check-item input {
    width: auto;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 800;
}

.badge.active {
    background: #dcfce7;
    color: #166534;
}

.badge.inactive {
    background: #e5e7eb;
    color: #374151;
}

.alert {
    background: #fee2e2;
    color: #991b1b;
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 18px;
    font-weight: 700;
}

.login-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #030712, #111827, #374151);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.login-box {
    width: 380px;
    background: #ffffff;
    border-radius: 22px;
    padding: 36px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.login-box h1 {
    margin: 0;
    color: #0f172a;
    font-size: 30px;
    letter-spacing: 1px;
}

.login-box p {
    margin: 8px 0 24px;
    color: #6b7280;
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-box button {
    background: #0f172a;
    color: #ffffff;
    border: 0;
    border-radius: 12px;
    padding: 13px;
    font-weight: 800;
    cursor: pointer;
}

.app-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    inset: 0;
    background: rgba(3, 7, 18, 0.68);
    padding: 36px 18px;
    overflow-y: auto;
}

.app-modal.show {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.app-modal-card {
    width: 100%;
    max-width: 900px;
    background: #ffffff;
    border-radius: 22px;
    padding: 28px;
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
    animation: modalPop 0.15s ease-out;
}

.app-modal-card.small {
    max-width: 540px;
}

.app-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 22px;
}

.app-modal-head h2 {
    margin: 0;
    color: #111827;
    font-size: 24px;
}

.app-modal-head p {
    margin: 8px 0 0;
    color: #6b7280;
}

.app-modal-close {
    border: 0;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #111827;
    font-size: 26px;
    cursor: pointer;
    flex: 0 0 auto;
}

.app-modal-close:hover {
    background: #e5e7eb;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.summary-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 18px;
}

.summary-label {
    color: #6b7280;
    font-size: 14px;
    font-weight: 700;
}

.summary-value {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 900;
    color: #111827;
}

.summary-value.profit,
.text-profit {
    color: #166534;
}

.summary-value.expense,
.text-danger {
    color: #991b1b;
}

.profit-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
}

.card-head.mini {
    margin-bottom: 14px;
}

.month-filter {
    display: flex;
    gap: 10px;
    align-items: center;
}

.month-filter input {
    width: 170px;
}

.coming-soon {
    min-height: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #374151;
    text-align: center;
}

.coming-icon {
    font-size: 48px;
    margin-bottom: 14px;
}

.coming-soon h2 {
    margin: 0;
    font-size: 26px;
    color: #111827;
}

.coming-soon p {
    margin: 12px 0 0;
    color: #6b7280;
    line-height: 1.7;
}

@keyframes modalPop {
    from {
        transform: translateY(12px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 태블릿/모바일 */
@media (max-width: 1100px) {
    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }

    .sidebar-open-btn {
        display: inline-flex;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 10000;
        width: 42px;
        height: 42px;
        border: 0;
        border-radius: 12px;
        background: #0f172a;
        color: #ffffff;
        font-size: 22px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
    }

    .sidebar-close-btn {
        display: inline-flex;
        position: absolute;
        top: 16px;
        right: 16px;
        width: 36px;
        height: 36px;
        border: 0;
        border-radius: 999px;
        background: #1f2937;
        color: #ffffff;
        font-size: 24px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
    }

    body:not(.sidebar-collapsed) .sidebar-open-btn {
        display: none;
    }

    .layout {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        z-index: 9998;
        width: 270px;
        height: 100vh;
        transform: translateX(0);
        transition: transform 0.2s ease;
    }

    .brand {
        margin-top: 42px;
    }

    .main {
        margin-left: 0;
        max-width: 100vw;
        padding: 70px 16px 16px;
    }

    body:not(.sidebar-collapsed):not(.login-page)::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(3, 7, 18, 0.45);
        z-index: 9997;
    }

    body:not(.sidebar-collapsed):not(.login-page) .main {
        pointer-events: none;
    }

    .page-head,
    .card-head {
        flex-direction: column;
        align-items: stretch;
    }

    .page-head h1 {
        font-size: 23px;
    }

    .page-head p,
    .card-head p {
        font-size: 14px;
    }

    .page-head .btn-primary,
    .card-head .btn-primary,
    .page-head button,
    .card-head button {
        width: 100%;
    }

    .narrow-card,
    .form-card,
    .filter-card {
        max-width: 100%;
    }

    .card {
        padding: 14px;
        border-radius: 14px;
    }

    .search-form,
    .compact-search,
    .grid-form,
    .inline-form,
    .visit-top,
    .treatment-form,
    .user-form {
        grid-template-columns: 1fr;
    }

    .search-actions,
    .form-actions {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .btn-primary,
    .btn-secondary,
    .btn-small {
        width: 100%;
        text-align: center;
    }

    table {
        min-width: 900px;
        font-size: 13px;
    }

    .simple-table {
        min-width: 650px;
    }

    th,
    td {
        padding: 9px 8px;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
        font-size: 15px;
    }

    .checkbox-area {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .label-title {
        grid-column: 1 / -1;
    }

    .check-item {
        justify-content: flex-start;
        border-radius: 12px;
    }

    .app-modal {
        padding: 12px;
    }

    .app-modal-card,
    .app-modal-card.small {
        max-width: 100%;
        padding: 18px;
        border-radius: 16px;
    }

    .summary-grid,
    .profit-layout {
        grid-template-columns: 1fr;
    }

    .month-filter {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .month-filter input,
    .month-filter button {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .main {
        padding: 70px 10px 10px;
    }

    .sidebar {
        width: 260px;
    }

    .page-head h1 {
        font-size: 21px;
    }

    .card {
        padding: 10px;
        border-radius: 12px;
    }

    .checkbox-area {
        grid-template-columns: 1fr;
    }

    table {
        min-width: 760px;
    }

    .simple-table {
        min-width: 560px;
    }

    .memo-cell {
        min-width: 180px;
    }

    .count-cell {
        min-width: 150px;
    }

    .login-box {
        width: 100%;
        padding: 26px;
    }
}

.icon-btn.disabled {
    background: #e5e7eb;
    color: #6b7280;
    cursor: not-allowed;
    border-color: #d1d5db;
}

.status-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: -10px 0 18px;
    color: #4b5563;
    font-size: 13px;
    font-weight: 700;
}

.status-summary span {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    padding: 6px 10px;
    border-radius: 999px;
}

.status-summary b {
    color: #d1d5db;
}

.treatment-select-area {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 16px;
}

.treatment-category-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-top: 12px;
}

.treatment-category-box {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 14px;
}

.treatment-category-title {
    font-weight: 900;
    color: #111827;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.treatment-check-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.treatment-check-list .check-item {
    border-radius: 12px;
}

.customer-main-table {
    min-width: 900px;
}

.name-link {
    border: 0;
    background: transparent;
    color: #0f172a;
    font-weight: 900;
    cursor: pointer;
    font-size: 14px;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.name-link:hover {
    color: #2563eb;
}

.detail-section {
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
    background: #ffffff;
}

.detail-section h3 {
    margin: 0 0 14px;
    font-size: 17px;
    color: #111827;
}

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

.detail-grid div {
    background: #f9fafb;
    border-radius: 12px;
    padding: 12px;
}

.detail-grid b {
    display: block;
    color: #6b7280;
    font-size: 13px;
    margin-bottom: 6px;
}

.detail-grid span {
    color: #111827;
    font-weight: 700;
}

.full-detail {
    grid-column: 1 / -1;
}

.memo-box {
    background: #f9fafb;
    border-radius: 12px;
    padding: 14px;
    min-height: 90px;
    white-space: pre-wrap;
    line-height: 1.6;
}

.visit-card-head {
    align-items: flex-start;
}

.visit-card-head h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.small-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e0f2fe;
    color: #075985;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 800;
}

.visit-search-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-bottom: 18px;
    padding: 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
}

.visit-search-bar input {
    height: 42px;
}

.visit-count-link {
    border: 0;
    background: #e0f2fe;
    color: #075985;
    font-weight: 900;
    border-radius: 999px;
    padding: 6px 12px;
    cursor: pointer;
}

.visit-count-link:hover {
    background: #bae6fd;
}

.customer-inner-search {
    display: grid;
    grid-template-columns: 1.4fr 180px 180px auto;
    gap: 10px;
    margin-bottom: 18px;
    padding: 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
}

.customer-inner-search input,
.customer-inner-search select {
    height: 42px;
}

.customer-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.customer-card-head .btn-primary {
    flex-shrink: 0;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 18px;
    font-weight: 800;
}

.pagination .disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.error-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #030712, #111827, #374151);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.error-box {
    width: 100%;
    max-width: 460px;
    background: #ffffff;
    border-radius: 24px;
    padding: 38px 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    text-align: center;
}

.error-box h1 {
    margin: 0;
    color: #111827;
    font-size: 26px;
}

.error-box p {
    margin: 14px 0 24px;
    color: #6b7280;
    line-height: 1.6;
}

.error-box .btn-primary {
    width: 100%;
}

@media (max-width: 900px) {
    .customer-inner-search {
        grid-template-columns: 1fr;
    }

    .customer-inner-search .btn-secondary {
        width: 100%;
    }
}

@media (max-width: 900px) {
    .visit-search-bar {
        grid-template-columns: 1fr;
    }

    .visit-search-bar .btn-secondary {
        width: 100%;
    }
}

@media (max-width: 900px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .customer-main-table {
        min-width: 760px;
    }
}

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