/* ========== 摩瑪建材 CRM 系統樣式 ========== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    min-height: 100vh;
}

/* ========== 登入頁 ========== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.login-box {
    width: 100%;
    max-width: 380px;
    padding: 2.5rem;
    background: #1e293b;
    border-radius: 16px;
    border: 1px solid rgba(212, 175, 55, 0.2);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo h1 {
    color: #d4af37;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.login-logo p {
    color: #94a3b8;
    font-size: 0.9rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-form input {
    padding: 1rem;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0f172a;
    color: #fff;
    font-size: 1rem;
}

.login-form input:focus {
    outline: none;
    border-color: #d4af37;
}

.login-form button {
    padding: 1rem;
    background: linear-gradient(135deg, #d4af37, #aa8a2e);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.login-form button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.4);
}

.login-error {
    color: #ef4444;
    font-size: 0.9rem;
    text-align: center;
    display: none;
}

/* ========== 主應用 ========== */
.main-app {
    display: none;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: #1e293b;
    border-bottom: 1px solid #334155;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-brand h1 {
    color: #d4af37;
    font-size: 1.25rem;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-user span {
    color: #94a3b8;
}

.logout-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid #475569;
    border-radius: 6px;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: #334155;
    color: #fff;
}

/* Navigation */
.app-nav {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 2rem;
    background: #1e293b;
    border-bottom: 1px solid #334155;
}

.nav-item {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #94a3b8;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-item:hover {
    background: #334155;
    color: #fff;
}

.nav-item.active {
    background: rgba(212, 175, 55, 0.2);
    color: #d4af37;
}

/* Content */
.app-content {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.page-content {
    display: none;
}

/* ========== 儀表板 ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: #1e293b;
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid #334155;
}

.stat-card .stat-label {
    color: #94a3b8;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.stat-card .stat-value {
    color: #fff;
    font-size: 2rem;
    font-weight: 700;
}

.stat-card.highlight {
    border-color: rgba(212, 175, 55, 0.3);
    background: linear-gradient(135deg, #1e293b, rgba(212, 175, 55, 0.1));
}

.stat-card.highlight .stat-value {
    color: #d4af37;
}

/* Activities */
.section-title {
    font-size: 1.1rem;
    color: #d4af37;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #334155;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: #1e293b;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.activity-type {
    min-width: 80px;
    font-size: 0.85rem;
}

.activity-info {
    flex: 1;
}

.activity-customer {
    font-weight: 500;
}

.activity-note {
    font-size: 0.85rem;
    color: #94a3b8;
}

.activity-date {
    color: #64748b;
    font-size: 0.85rem;
}

/* ========== 客戶列表 ========== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 1.5rem;
    color: #d4af37;
}

.page-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-input {
    padding: 0.6rem 1rem;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0f172a;
    color: #fff;
    width: 200px;
}

.filter-select {
    padding: 0.6rem 1rem;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0f172a;
    color: #fff;
}

.btn-primary {
    padding: 0.6rem 1.25rem;
    background: linear-gradient(135deg, #d4af37, #aa8a2e);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.btn-danger {
    padding: 0.6rem 1.25rem;
    background: #dc2626;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
    cursor: pointer;
}

/* Customer Cards */
.customer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.customer-card {
    background: #1e293b;
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid #334155;
    cursor: pointer;
    transition: all 0.2s;
}

.customer-card:hover {
    border-color: rgba(212, 175, 55, 0.5);
    transform: translateY(-2px);
}

.customer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.customer-name {
    font-size: 1.1rem;
    font-weight: 600;
}

.level-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    color: #fff;
}

.customer-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #94a3b8;
}

/* ========== 業務列表 ========== */
.sales-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: #1e293b;
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid #334155;
    margin-bottom: 1rem;
}

.sales-avatar {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #d4af37, #aa8a2e);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
}

.sales-info {
    flex: 1;
}

.sales-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.sales-phone, .sales-region {
    font-size: 0.85rem;
    color: #94a3b8;
}

.sales-stats {
    display: flex;
    gap: 2rem;
}

.sales-stats .stat-item {
    text-align: center;
}

.sales-stats .stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: #d4af37;
}

.sales-stats .stat-label {
    font-size: 0.75rem;
    color: #64748b;
}

.sales-actions {
    display: flex;
    gap: 0.5rem;
}

.sales-actions button {
    padding: 0.5rem 1rem;
    background: #334155;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
}

.sales-actions button:hover {
    background: #475569;
}

/* ========== 報表 ========== */
.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.report-card {
    background: #1e293b;
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid #334155;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: #0f172a;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.rank {
    width: 28px;
    height: 28px;
    background: #334155;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}

.ranking-item:first-child .rank {
    background: #d4af37;
    color: #000;
}

.rank-name {
    flex: 1;
    font-weight: 500;
}

.rank-deals {
    color: #64748b;
    font-size: 0.85rem;
}

.rank-revenue {
    color: #d4af37;
    font-weight: 600;
}

.dist-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem;
    background: #0f172a;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

/* ========== Modal ========== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.open {
    display: flex;
}

.modal-box {
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    background: #1e293b;
    border-radius: 16px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    background: #0f172a;
    border-bottom: 1px solid #334155;
}

.modal-header h2 {
    color: #d4af37;
    font-size: 1.25rem;
}

.modal-close {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-content {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(90vh - 150px);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #94a3b8;
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0f172a;
    color: #fff;
    font-size: 0.95rem;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #d4af37;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: #0f172a;
    border-top: 1px solid #334155;
}

.btn-secondary {
    padding: 0.6rem 1.25rem;
    background: #334155;
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
}

/* Contact Form */
.contacts-section h4 {
    color: #94a3b8;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.contact-form-item {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr auto;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.contact-form-item input {
    padding: 0.6rem;
    border: 1px solid #334155;
    border-radius: 6px;
    background: #0f172a;
    color: #fff;
    font-size: 0.85rem;
}

.remove-contact {
    width: 32px;
    background: #dc2626;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
}

.add-contact-btn {
    padding: 0.5rem 1rem;
    background: #334155;
    border: none;
    border-radius: 6px;
    color: #d4af37;
    cursor: pointer;
    font-size: 0.85rem;
}

/* Detail Modal */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.detail-header h2 {
    font-size: 1.5rem;
}

.detail-section {
    margin-bottom: 1.5rem;
}

.detail-section h3 {
    color: #d4af37;
    font-size: 1rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #334155;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #1e293b;
}

.detail-row span:first-child {
    color: #64748b;
}

.contact-card {
    background: #0f172a;
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.contact-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.contact-title {
    color: #64748b;
    font-weight: normal;
    font-size: 0.85rem;
}

.contact-info {
    font-size: 0.85rem;
    color: #94a3b8;
}

.record-item {
    background: #0f172a;
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.record-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.record-type {
    color: #d4af37;
    font-size: 0.85rem;
}

.record-date {
    color: #64748b;
    font-size: 0.85rem;
}

.record-note {
    color: #94a3b8;
    font-size: 0.9rem;
}

.record-amount {
    color: #10b981;
    font-weight: 600;
    margin-top: 0.5rem;
}

.detail-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e293b;
    color: #fff;
    padding: 1rem 2rem;
    border-radius: 8px;
    border: 1px solid #d4af37;
    opacity: 0;
    transition: all 0.3s;
    z-index: 2000;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Empty State */
.empty-text {
    text-align: center;
    color: #64748b;
    padding: 2rem;
}

/* RWD */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .app-nav {
        overflow-x: auto;
        padding: 0.75rem 1rem;
    }

    .app-content {
        padding: 1rem;
    }

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

    .page-actions {
        flex-direction: column;
    }

    .search-input {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .contact-form-item {
        grid-template-columns: 1fr 1fr;
    }

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

    .sales-card {
        flex-direction: column;
        text-align: center;
    }

    .sales-stats {
        justify-content: center;
    }

    .report-grid {
        grid-template-columns: 1fr;
    }
}
