/* ========== 摩瑪建材 客戶管理後台樣式 ========== */

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-card: #1a1a1a;
    --gold: #c9a962;
    --gold-light: #e8d5a3;
    --gold-dark: #8b7355;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --text-muted: #666;
    --border: rgba(201, 169, 98, 0.2);
    --success: #4a9c6d;
    --warning: #d69e2e;
    --danger: #e53e3e;
    --info: #4299e1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans TC', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* Header */
.admin-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gold);
}

.page-title {
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding-left: 1.5rem;
    border-left: 1px solid var(--border);
}

.back-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.875rem;
    transition: all 0.3s;
}

.back-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
}

/* Admin Navigation */
.admin-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.admin-nav > a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: all 0.3s;
}

.admin-nav > a:hover {
    color: var(--gold);
    background: rgba(201, 169, 98, 0.1);
}

.nav-dropdown {
    position: relative;
}

.nav-dropdown-btn {
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
}

.nav-dropdown:hover .nav-dropdown-btn {
    color: var(--gold);
    background: rgba(201, 169, 98, 0.1);
}

.nav-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 150px;
    padding: 0.5rem 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 200;
}

.nav-dropdown:hover .nav-dropdown-content {
    display: block;
}

.nav-dropdown-content a {
    display: block;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.nav-dropdown-content a:hover {
    color: var(--gold);
    background: rgba(201, 169, 98, 0.1);
}

@media (max-width: 768px) {
    .admin-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .admin-nav {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* Main */
.admin-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Stats Section */
.stats-section {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.3s;
}

.stat-card:hover {
    border-color: var(--gold);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.total { background: rgba(201, 169, 98, 0.2); }
.stat-icon.level1 { background: rgba(66, 153, 225, 0.2); }
.stat-icon.level2 { background: rgba(74, 156, 109, 0.2); }
.stat-icon.level3 { background: rgba(214, 158, 46, 0.2); }

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Toolbar */
.toolbar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
}

.search-box input {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    width: 280px;
    transition: border-color 0.3s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--gold);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
}

.filter-select {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.625rem 1rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.3s;
}

.filter-select:focus {
    outline: none;
    border-color: var(--gold);
}

.tool-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.625rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tool-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
}

.tool-btn.primary {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--bg-primary);
}

.tool-btn.primary:hover {
    background: var(--gold-light);
    border-color: var(--gold-light);
}

.tool-btn.danger {
    border-color: var(--danger);
    color: var(--danger);
}

.tool-btn.danger:hover {
    background: var(--danger);
    color: white;
}

.tool-btn.success {
    border-color: #28a745;
    color: #28a745;
    background: transparent;
}

.tool-btn.success:hover {
    background: #28a745;
    color: white;
}

/* Table Section */
.table-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.customer-table {
    width: 100%;
    border-collapse: collapse;
}

.customer-table th,
.customer-table td {
    padding: 1rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.customer-table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.customer-table tr:hover {
    background: rgba(201, 169, 98, 0.05);
}

.customer-table tr:last-child td {
    border-bottom: none;
}

.customer-name {
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
}

.customer-name:hover {
    color: var(--gold);
}

.type-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.type-badge.M-子公司 { background: rgba(74, 156, 109, 0.2); color: var(--success); }
.type-badge.M-注資經銷商 { background: rgba(201, 169, 98, 0.2); color: var(--gold); }
.type-badge.M-未注資經銷商 { background: rgba(214, 158, 46, 0.2); color: var(--warning); }
.type-badge.M-無底薪業務 { background: rgba(160, 160, 160, 0.2); color: var(--text-secondary); }
.type-badge.BNI大台中南區會員 { background: rgba(66, 153, 225, 0.2); color: var(--info); }
.type-badge.設計師-工程行 { background: rgba(138, 99, 210, 0.2); color: #a78bfa; }

.discount-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(201, 169, 98, 0.2);
    color: var(--gold);
}

.parent-link {
    color: var(--gold);
    cursor: pointer;
    text-decoration: none;
}

.parent-link:hover {
    text-decoration: underline;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 4px;
    transition: all 0.2s;
    margin-right: 0.25rem;
}

.action-btn:hover {
    background: var(--bg-secondary);
    color: var(--gold);
}

.action-btn.delete:hover {
    color: var(--danger);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

/* Tree Section */
.tree-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}

.tree-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gold);
    margin-bottom: 1rem;
}

.tree-container {
    padding: 1rem;
}

.tree-node {
    margin-left: 1.5rem;
    padding: 0.5rem 0;
    border-left: 2px solid var(--border);
    padding-left: 1rem;
}

.tree-node.root {
    margin-left: 0;
    border-left: none;
    padding-left: 0;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tree-item:hover {
    background: rgba(201, 169, 98, 0.1);
    border-color: var(--gold);
}

.tree-item .icon {
    font-size: 1.25rem;
}

.tree-item .name {
    font-weight: 600;
}

.tree-item .type {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: auto;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 500px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal.modal-large {
    width: 700px;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gold);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.3s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-group {
    flex: 1;
}

.form-group.full-width {
    flex: 100%;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-group .required {
    color: var(--danger);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--gold);
}

.form-group textarea {
    resize: vertical;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    position: sticky;
    bottom: 0;
    background: var(--bg-card);
}

/* View Modal Details */
.detail-section {
    margin-bottom: 1.5rem;
}

.detail-section h4 {
    font-size: 0.875rem;
    color: var(--gold);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.detail-row {
    display: flex;
    padding: 0.5rem 0;
}

.detail-label {
    width: 120px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.detail-value {
    flex: 1;
    color: var(--text-primary);
}

/* Toast */
.admin-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--gold);
    color: var(--bg-primary);
    padding: 0.875rem 1.5rem;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 600;
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.admin-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 1024px) {
    .stats-section {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .admin-header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }

    .admin-main {
        padding: 1rem;
    }

    .stats-section {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-left,
    .toolbar-right {
        flex-direction: column;
        width: 100%;
    }

    .search-box input,
    .filter-select {
        width: 100%;
    }

    .tool-btn {
        width: 100%;
        justify-content: center;
    }

    .table-section {
        overflow-x: auto;
    }

    .customer-table {
        min-width: 800px;
    }

    .form-row {
        flex-direction: column;
    }

    .modal.modal-large {
        width: 95%;
    }
}
