@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --border: #e5e9f2;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --radius: 14px;
    --shadow: 0 15px 40px rgba(15, 23, 42, 0.08);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Microsoft YaHei', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

button,
input,
select,
textarea {
    font: inherit;
}

.hidden {
    display: none !important;
}

.muted {
    color: var(--muted);
    font-size: 12px;
}

/* ---------- Buttons ---------- */
.btn {
    border: none;
    border-radius: 999px;
    padding: 10px 18px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: #eef2ff;
    color: var(--primary);
}

.btn-outline {
    background: #fff;
    color: var(--primary);
    border: 1px solid #cbd5f5;
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.link-btn {
    border: none;
    background: none;
    color: var(--primary);
    cursor: pointer;
    padding: 0;
    font-weight: 600;
}

.link-btn.danger {
    color: var(--danger);
}

/* ---------- Auth View ---------- */
.auth-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(circle at top, #3b82f6, #1e1b4b);
}

.auth-card {
    width: min(420px, 100%);
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.brand-title {
    font-size: 20px;
    font-weight: 600;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 13px;
}

.auth-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.auth-tab {
    border: none;
    padding: 10px 0;
    border-radius: 10px;
    font-weight: 600;
    background: #f3f4f6;
    color: var(--muted);
    cursor: pointer;
}

.auth-tab.active {
    background: #e0e7ff;
    color: var(--primary);
}

.auth-form {
    display: none;
    flex-direction: column;
    gap: 14px;
}

.auth-form.active {
    display: flex;
}

.auth-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
    color: var(--muted);
}

.auth-form input {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: #f9fafb;
}

.auth-form input:focus {
    outline: 2px solid #c7d2fe;
    background: #fff;
}

/* ---------- App View ---------- */
.app-view {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 24px 60px;
}

.app-header {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    gap: 24px;
}

.app-header h1 {
    font-size: 26px;
    margin-bottom: 4px;
}

.app-header .muted {
    color: var(--muted);
    font-size: 14px;
}

.user-box {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-name {
    font-weight: 600;
}

.user-email {
    color: var(--muted);
    font-size: 13px;
}

.app-body {
    margin-top: 28px;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 24px;
}

/* 合同管理页面：列表占满整个宽度 */
.app-body.full-width {
    grid-template-columns: 1fr;
}

.list-panel,
.form-panel {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.input-group {
    background: #f3f4f6;
    border-radius: 999px;
    padding: 0 14px;
    display: flex;
    align-items: center;
}

.input-group input {
    border: none;
    background: transparent;
    padding: 10px 6px;
    min-width: 200px;
}

.filters select {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 10px 14px;
    background: #fff;
}

.table-wrapper {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    overflow-y: hidden;
}

.table-wrapper.small {
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead {
    background: #f8fafc;
}

th,
td {
    text-align: left;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    color: var(--muted);
    font-size: 13px;
}

tbody tr:hover {
    background: #f9fafb;
}

.empty-row {
    text-align: center;
    color: var(--muted);
    padding: 24px !important;
}

.text-right {
    text-align: right;
}

.status-pill {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.status-pill[data-status="draft"] {
    background: #fff7ed;
    color: #c2410c;
}

.status-pill[data-status="sent"] {
    background: #e0f2fe;
    color: #0369a1;
}

.status-pill[data-status="confirmed"] {
    background: #ecfdf5;
    color: #047857;
}

/* ---------- Form ---------- */
#quoteForm {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.form-grid label,
.full-width {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.form-grid input,
.form-grid select,
.full-width textarea {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: #f9fafb;
}

.section-block {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

#serviceTableBody input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    background: #fff;
}

.service-subtotal {
    font-weight: 600;
}

.description-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.description-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f9fafb;
}

.description-item input,
.description-item textarea {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    background: #fff;
}

.description-item textarea {
    min-height: 60px;
    resize: vertical;
}

.description-list.empty {
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 18px;
    color: var(--muted);
    text-align: center;
}

.picker-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.picker-modal.hidden {
    display: none !important;
}

.picker-content {
    width: min(500px, 90vw);
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 80vh;
}

.picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.picker-search input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 10px 14px;
}

.picker-list {
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    flex: 1;
}

.picker-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.6);
    gap: 12px;
}

.picker-item:last-child {
    border-bottom: none;
}

.picker-item h4 {
    margin: 0;
    font-size: 15px;
}

.picker-item p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.admin-view {
    max-width: 1400px;
    margin: 0 auto;
}

.admin-tabs {
    margin-top: 24px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.admin-tab {
    border: 1px solid var(--border);
    background: #fff;
    padding: 10px 18px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
}

.admin-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.admin-panel {
    display: none;
    margin-top: 20px;
}

.admin-panel.active {
    display: block;
}

.admin-panel-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.admin-table-wrapper {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.admin-form {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    background: #fff;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
}

.total-row strong {
    font-size: 20px;
    color: var(--primary);
}

.form-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.form-actions > .btn {
    flex: 1;
    min-width: 120px;
    text-align: center;
}

.quote-export-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    padding: 14px 16px;
    margin-bottom: 20px;
    background: linear-gradient(135deg, #f0f7ff 0%, #eef4ff 100%);
    border: 1px solid #c7d9f7;
    border-radius: var(--radius);
}

.quote-export-bar .quote-export-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-right: 0;
}

.quote-export-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.quote-list-actions {
    min-width: 200px;
    max-width: 280px;
    white-space: normal;
    vertical-align: top;
}

.quote-action-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    align-items: center;
    margin-bottom: 8px;
}

.quote-action-stack:last-child {
    margin-bottom: 0;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: #fff;
    padding: 12px 20px;
    border-radius: 999px;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 999;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, -6px);
}

.toast.error {
    background: var(--danger);
}

.toast.success {
    background: #16a34a;
}

.toast.info {
    background: var(--primary);
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .app-body {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .app-view {
        padding: 20px 16px 50px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .filters {
        flex-direction: column;
        width: 100%;
    }

    .input-group input,
    .filters select {
        width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }
}

