:root {
    --primary: #2d6a4f;
    --primary-light: #40916c;
    --primary-dark: #1b4332;
    --accent: #d8f3dc;
    --danger: #c1121f;
    --warning: #e85d04;
    --bg: #f0f4f1;
    --card: #ffffff;
    --text: #1a1a2e;
    --text-muted: #6c757d;
    --border: #dee2e6;
    --sidebar-width: 240px;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
}

.login-container { width: 100%; max-width: 420px; padding: 20px; }

.login-card {
    background: var(--card);
    border-radius: 12px;
    padding: 40px 32px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.login-brand { text-align: center; margin-bottom: 32px; }
.brand-icon-lg { font-size: 48px; display: block; margin-bottom: 12px; }
.login-brand h1 { font-size: 22px; color: var(--primary-dark); }
.login-brand p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.login-hint { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 16px; }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--primary-dark);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-icon { font-size: 28px; }
.sidebar-brand h1 { font-size: 18px; font-weight: 600; }
.sidebar-brand small { font-size: 11px; opacity: 0.7; display: block; }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-size: 14px;
    transition: all 0.2s;
}

.nav-item:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 500; }
.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}
.nav-icon svg { width: 18px; height: 18px; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.user-avatar {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.user-info strong { display: block; font-size: 14px; }
.user-info small { font-size: 12px; opacity: 0.7; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px 32px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h2 { font-size: 24px; font-weight: 600; color: var(--primary-dark); }

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }
.mt-4 { margin-top: 24px; }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
}

.stat-icon { font-size: 32px; }
.stat-value { display: block; font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-muted); }

.stat-card-action { padding: 0; }
.quick-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    text-decoration: none;
    color: var(--primary);
    font-weight: 500;
    width: 100%;
    transition: background 0.2s;
}

.quick-link:hover { background: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
}

.data-table td {
    padding: 12px;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tr:hover td { background: #fafbfa; }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success { background: #d8f3dc; color: var(--primary-dark); }
.badge-danger { background: #fde8e8; color: var(--danger); }
.badge-warning { background: #fff3e0; color: var(--warning); }
.badge-muted { background: #e9ecef; color: var(--text-muted); }

/* Alerts on rows */
.row-alert-expired td:first-child { border-left: 3px solid var(--danger); }
.row-alert-low td:first-child { border-left: 3px solid var(--warning); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45,106,79,0.15);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 12px; }
.checkbox-group label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a0101a; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-block { width: 100%; }

.btn-group { display: flex; gap: 6px; }

/* Toolbar */
.toolbar { margin-bottom: 16px; }
.search-box input {
    width: 100%;
    max-width: 400px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
}

.search-box-lg input { max-width: 100%; font-size: 16px; padding: 12px 16px; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.show { display: flex; }

.modal-content {
    background: var(--card);
    border-radius: 12px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-lg { max-width: 640px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.alert-error { background: #fde8e8; color: var(--danger); }
.alert-success { background: #d8f3dc; color: var(--primary-dark); }

/* Workbench */
.workbench-layout { max-width: 800px; }
.search-results { margin-top: 12px; }

.search-result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.search-result-item:hover { border-color: var(--primary); background: var(--accent); }

.patient-info-bar {
    display: flex;
    gap: 24px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
}

.section-title { font-size: 15px; font-weight: 600; margin: 20px 0 12px; color: var(--primary-dark); }

.package-select-list { display: flex; flex-direction: column; gap: 8px; }

.package-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}

.package-option:hover { border-color: var(--primary-light); }
.package-option.selected { border-color: var(--primary); background: var(--accent); }
.package-option.disabled { opacity: 0.5; cursor: not-allowed; }

.package-option-info strong { display: block; }
.package-option-info small { color: var(--text-muted); font-size: 12px; }

/* Timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 8px; top: 0; bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -20px; top: 6px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--card);
}

.timeline-date { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.timeline-content {
    background: var(--bg);
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
}

.timeline-content strong { color: var(--primary-dark); }

/* Patient detail */
.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
}

.detail-header h3 { font-size: 22px; }

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.detail-info p { margin-bottom: 8px; font-size: 14px; }
.detail-info strong { color: var(--text-muted); font-weight: 500; margin-right: 8px; }

.package-card {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
}

.package-card.alert-expired { border-color: var(--danger); background: #fff5f5; }
.package-card.alert-low { border-color: var(--warning); background: #fff8f0; }

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

.text-muted { color: var(--text-muted); font-size: 14px; margin-bottom: 12px; }
.help-list { padding-left: 20px; font-size: 14px; }
.help-list li { margin-bottom: 8px; }
.loading { text-align: center; padding: 40px; color: var(--text-muted); }

code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

.toast {
    position: fixed;
    top: 20px; right: 20px;
    padding: 12px 20px;
    border-radius: var(--radius);
    color: #fff;
    font-size: 14px;
    z-index: 9999;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow);
}

.toast-success { background: var(--primary); }
.toast-error { background: var(--danger); }

.toolbar-wrap { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.toolbar-filters { align-items: flex-end; gap: 12px; }
.toolbar-filters .form-group { margin-bottom: 0; min-width: 140px; }

.row-voided { opacity: 0.65; }
.timeline-item.voided { opacity: 0.65; }
.timeline-item.voided .timeline-content { text-decoration: line-through; text-decoration-color: rgba(0,0,0,0.25); }

.audit-log-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 12px;
}
.audit-log-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 14px; }
.audit-log-head span { color: var(--text-muted); font-size: 13px; }
.audit-log-note { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.audit-log-diff { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 13px; }
.audit-log-col h5 { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.audit-log-col div { margin-bottom: 4px; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-brand div, .sidebar-brand small, .nav-item span:not(.nav-icon), .user-info div, .sidebar-footer .btn { display: none; }
    .main-content { margin-left: 60px; padding: 16px; }
    .form-row, .detail-grid { grid-template-columns: 1fr; }
    .audit-log-diff { grid-template-columns: 1fr; }
}
