/* ==========================================
   薯小劲口腔诊所管理系统 - 样式
   ========================================== */

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2c7be5;
    --primary-dark: #1a68d1;
    --primary-light: #e8f0fe;
    --success: #00d97d;
    --warning: #f6c343;
    --danger: #e63757;
    --info: #39afd1;
    --secondary: #95aac9;
    --dark: #12263f;
    --gray: #6c757d;
    --light: #f5f7fa;
    --white: #ffffff;
    --border: #e3ebf6;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 4px rgba(18, 38, 63, 0.08);
    --shadow-lg: 0 2px 12px rgba(0, 0, 0, 0.08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    --sidebar-width: 240px;
}

html, body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--dark);
    background: var(--light);
    line-height: 1.5;
}

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

/* ==========================================
   Login Page
   ========================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, var(--primary) 100%);
    padding: 20px;
}

.login-container { width: 100%; max-width: 400px; }

.login-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
}

.login-header { text-align: center; margin-bottom: 28px; }

.login-logo {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-header h1 {
    font-size: 22px;
    color: var(--dark);
    margin-bottom: 4px;
}

.login-header p {
    color: var(--gray);
    font-size: 14px;
}

.login-form .form-group { margin-bottom: 18px; }

.login-form label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 13px;
    color: var(--gray);
}

/* ==========================================
   App Layout
   ========================================== */
.app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: #d4d9e3;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo { font-size: 28px; }

.sidebar-title h2 {
    font-size: 14px;
    color: var(--white);
    margin-bottom: 2px;
}

.sidebar-role {
    font-size: 11px;
    color: var(--secondary);
}

.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: #a8b4c9;
    font-size: 14px;
    transition: all 0.2s;
    text-decoration: none;
    gap: 10px;
}

.nav-item:hover {
    background: rgba(255,255,255,0.06);
    color: var(--white);
    text-decoration: none;
}

.nav-item.active {
    background: rgba(44, 123, 229, 0.2);
    color: var(--primary);
    border-right: 3px solid var(--primary);
}

.nav-icon { font-size: 16px; }
.nav-text { font-size: 13px; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 8px 0;
}

.logout-btn { color: var(--danger); }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding-bottom: 40px;
}

/* Top Bar */
.top-bar {
    background: var(--white);
    padding: 16px 28px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--dark);
    padding: 4px;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--dark);
}

.top-bar-actions {
    margin-left: auto;
}

.top-bar-date {
    color: var(--gray);
    font-size: 13px;
}

.content-wrapper {
    padding: 24px 28px;
}

/* ==========================================
   Common Components
   ========================================== */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: #edf2f9; color: var(--dark); }
.btn-secondary:hover { background: #d9e2f0; }

.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover { opacity: 0.9; }

.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { opacity: 0.9; }

.btn-warning { background: var(--warning); color: var(--dark); }

.btn-link { background: none; color: var(--primary); padding: 4px 8px; }
.btn-link:hover { background: var(--primary-light); }

.btn-block { width: 100%; justify-content: center; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    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: 15px;
    font-weight: 600;
}

.card-body { padding: 16px 20px; }

/* Form */
.form-group { margin-bottom: 14px; }

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 13px;
    color: var(--gray);
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    background: var(--white);
    color: var(--dark);
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(44, 123, 229, 0.1);
}

select.form-input { cursor: pointer; }

textarea.form-input {
    resize: vertical;
    min-height: 80px;
}

/* Table */
.table-responsive {
    overflow-x: auto;
}

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

.table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    background: #fafbfe;
    white-space: nowrap;
}

.table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.table tr:hover { background: #f8fafc; }

.table .text-center { text-align: center; }
.table .text-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.action-cell {
    white-space: nowrap;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    padding: 16px;
    gap: 4px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 4px 8px;
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--dark);
    background: transparent;
    transition: all 0.2s;
    text-decoration: none;
}

.page-link:hover {
    background: var(--light);
    text-decoration: none;
}

.page-link.active {
    background: var(--primary);
    color: var(--white);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: #e6f9ee; color: #00a854; }
.badge-warning { background: #fff8e6; color: #b68300; }
.badge-danger { background: #fce8ec; color: #c41e3a; }
.badge-info { background: #e6f4f9; color: #0088b3; }
.badge-secondary { background: #edf2f9; color: #6c757d; }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-icon-blue { background: var(--primary-light); }
.stat-icon-green { background: #e6f9ee; }
.stat-icon-orange { background: #fff8e6; }
.stat-icon-purple { background: #f0e6ff; }

.stat-number {
    font-size: 22px;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
}

.stat-label {
    font-size: 12px;
    color: var(--gray);
    margin-top: 2px;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.dashboard-grid .card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
}

/* Quick Actions */
.quick-actions {
    margin-bottom: 20px;
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* List Group */
.list-group { }

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: none; }

.list-item-title {
    font-weight: 500;
    font-size: 14px;
}

.list-item-sub {
    font-size: 12px;
    color: var(--gray);
    margin-top: 2px;
}

.list-item-main { }

.list-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Toolbar */
.page-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.search-box {
    display: flex;
    gap: 8px;
}

.search-box .form-input {
    width: 260px;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.date-navigation {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-picker { width: auto !important; }

/* Patient Detail */
.patient-detail-header {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.patient-summary {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 12px 0;
}

.patient-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
    flex-shrink: 0;
}

.patient-info h2 {
    font-size: 22px;
    margin-bottom: 4px;
}

.patient-info p {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    color: var(--gray);
    font-size: 13px;
}

.patient-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.patient-actions .btn { font-size: 12px; }

/* Tabs */
.detail-tabs {
    margin-bottom: 20px;
}

.tabs {
    display: flex;
    gap: 2px;
    background: var(--white);
    border-radius: var(--radius);
    padding: 4px;
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.tab {
    padding: 8px 18px;
    border: none;
    background: none;
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
    color: var(--gray);
    white-space: nowrap;
    transition: all 0.2s;
}

.tab.active {
    background: var(--primary);
    color: var(--white);
}

.tab:hover:not(.active) {
    background: var(--light);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Upload Grid */
.upload-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 16px;
}

.upload-item {
    background: var(--light);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}

.upload-item:hover { transform: scale(1.03); }

.upload-preview {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #edf2f9;
}

.upload-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-icon {
    font-size: 36px;
}

.upload-info {
    padding: 8px 10px;
}

.upload-name {
    font-size: 12px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-type {
    font-size: 11px;
    color: var(--gray);
}

/* Alerts */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 14px;
}

.alert-success { background: #e6f9ee; color: #00a854; }
.alert-error { background: #fce8ec; color: #c41e3a; }
.alert-warning { background: #fff8e6; color: #b68300; }
.alert-info { background: #e6f4f9; color: #0088b3; }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray);
}

.empty-state p { font-size: 14px; }

/* Text helpers */
.text-muted { color: var(--gray); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-center { text-align: center; }

.link { color: var(--primary); cursor: pointer; }
.link:hover { text-decoration: underline; }

/* Row highlights */
.row-warning { background: #fffff0; }

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    min-width: 200px;
    max-width: 400px;
}

.toast-success { background: var(--success); color: var(--white); }
.toast-error { background: var(--danger); color: var(--white); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 4px 24px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 1;
}

.modal-header h3 { font-size: 16px; }

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--gray);
    padding: 4px;
    line-height: 1;
}

.modal-close:hover { color: var(--dark); }

.modal-body { padding: 20px; }

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    position: sticky;
    bottom: 0;
    background: var(--white);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Stats page */
.stats-row {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.stat-item {
    text-align: center;
    min-width: 100px;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--dark);
}

.stat-label-sm {
    font-size: 11px;
    color: var(--gray);
    margin-top: 4px;
}

/* Bar chart */
.bar-chart { padding: 10px 0; }

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 240px;
    padding-top: 20px;
    overflow-x: auto;
}

.chart-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 60px;
}

.chart-bar {
    width: 36px;
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height 0.3s;
}

.chart-bar-value {
    font-size: 11px;
    color: var(--gray);
    white-space: nowrap;
}

.chart-bar-label {
    font-size: 11px;
    color: var(--gray);
}

/* Pie chart list */
.pie-chart-list { }

.pie-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

.pie-label {
    font-size: 13px;
    min-width: 80px;
    flex-shrink: 0;
}

.pie-bar-bg {
    flex: 1;
    height: 20px;
    background: var(--light);
    border-radius: 10px;
    overflow: hidden;
}

.pie-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 10px;
    transition: width 0.5s;
    min-width: 10px;
}

.pie-bar-purple { background: #7c3aed; }

.pie-value {
    font-size: 12px;
    color: var(--gray);
    min-width: 80px;
    text-align: right;
}

/* Settings Grid */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.settings-grid .card-wide {
    grid-column: 1 / -1;
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .main-content {
        margin-left: 0;
    }

    .menu-toggle {
        display: block;
    }

    .content-wrapper {
        padding: 16px;
    }

    .top-bar {
        padding: 12px 16px;
    }

    .page-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box { flex-direction: column; }
    .search-box .form-input { width: 100%; }
    .toolbar-actions { justify-content: flex-end; }

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

    .stat-card { padding: 14px; }
    .stat-number { font-size: 18px; }
    .stat-icon { width: 40px; height: 40px; font-size: 18px; }

    .patient-summary { flex-direction: column; text-align: center; }
    .patient-info p { justify-content: center; }
    .patient-actions { justify-content: center; }

    .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    .date-navigation { width: 100%; justify-content: center; }

    .chart-bars { gap: 4px; }
    .chart-bar-item { min-width: 40px; }
    .chart-bar { width: 28px; }

    .modal { max-width: 100%; margin: 10px; }

    .stats-row { gap: 16px; }
    .stat-item { min-width: 80px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .action-buttons { flex-direction: column; }
    .action-buttons .btn { width: 100%; justify-content: center; }
}
