/* ============ Variables ============ */
:root {
    --bg-primary: #FAF9F6;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F5F3F0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --accent: #C9A96E;
    --accent-hover: #B8956A;
    --accent-light: #E8DCC8;
    --success: #7BA07B;
    --danger: #E57373;
    --border: #E8E4DF;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* ============ Login Screen ============ */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    padding: 48px 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    max-width: 400px;
    width: 100%;
}

.login-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.login-card h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.btn-telegram {
    width: 100%;
    padding: 16px 24px;
    background: #0088CC;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: background 0.2s, transform 0.1s;
}

.btn-telegram:hover {
    background: #0077BB;
}

.btn-telegram:active {
    transform: scale(0.98);
}

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

/* ============ Sidebar ============ */
.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.admin-role {
    font-size: 12px;
    color: var(--accent);
    background: var(--accent-light);
    padding: 4px 8px;
    border-radius: 4px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    transition: all 0.2s;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent-hover);
    font-weight: 500;
}

.nav-icon {
    font-size: 18px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.btn-logout {
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* ============ Main Content ============ */
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 24px 32px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
}

/* ============ Stats Grid ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

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

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

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ============ Buttons ============ */
.btn-primary {
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    padding: 10px 20px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    padding: 6px 12px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:hover {
    background: #D32F2F;
}

.btn-danger.btn-sm {
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 4px;
}

/* ============ Filters Bar ============ */
.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-secondary);
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.filter-select {
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-secondary);
    cursor: pointer;
}

/* ============ Tables ============ */
.table-container {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.data-table th {
    background: var(--bg-tertiary);
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--bg-tertiary);
}

/* 社群管理表格欄位寬度 */
.col-check { width: 32px; }
.col-id    { width: 50px; }
.col-title { width: auto; } /* 自動填滿剩餘空間 */
.col-count { width: 60px; text-align: right; }
.col-status { width: 60px; text-align: center; }
.col-actions { width: 110px; }

/* ============ Status Badge ============ */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.status-badge.active {
    background: #E8F5E9;
    color: #4CAF50;
}

.status-badge.inactive {
    background: #FFEBEE;
    color: #F44336;
}

.status-badge.locked {
    background: #FFF3E0;
    color: #FF9800;
}

/* ============ Toggle Switch ============ */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #E57373;
    transition: 0.3s;
    border-radius: 24px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.toggle input:checked + .toggle-slider {
    background-color: #4CAF50;
}

.toggle input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

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

.page-btn {
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.page-btn:hover {
    background: var(--bg-tertiary);
}

.page-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

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

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    animation: slideUp 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
}

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

.modal-body {
    padding: 24px;
}

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

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

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

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-secondary);
}

.form-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

.form-checkbox input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions .btn-primary {
    flex: 1;
}

.form-actions .btn-secondary {
    flex: 1;
}

/* ============ Toast ============ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}

.toast {
    padding: 14px 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    min-width: 280px;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast-icon {
    font-size: 18px;
}

.toast-message {
    font-size: 14px;
}

/* ============ Animations ============ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .sidebar {
        width: 56px;
    }

    .sidebar-header h2,
    .admin-role,
    .nav-item span:last-child,
    .sidebar-footer span {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 14px;
    }

    .main-content {
        margin-left: 56px;
        padding: 12px 8px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .page-header h1 {
        font-size: 18px;
    }

    .filters-bar {
        flex-direction: column;
    }

    .data-table th,
    .data-table td {
        padding: 10px 6px;
        font-size: 12px;
    }

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

    .stat-card {
        padding: 14px 10px;
    }

    .stat-value {
        font-size: 20px;
    }
}

/* ============ Action Badge ============ */
.action-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    background: #E3F2FD;
    color: #1565C0;
}

.action-badge.grant { background: #E8F5E9; color: #2E7D32; }
.action-badge.revoke { background: #FFEBEE; color: #C62828; }
.action-badge.activate { background: #E8F5E9; color: #2E7D32; }
.action-badge.delete_partner { background: #FFEBEE; color: #C62828; }
.action-badge.batch_import { background: #E3F2FD; color: #1565C0; }
.action-badge.login { background: #F3E5F5; color: #7B1FA2; }

/* ============ Drop Zone ============ */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-tertiary);
    position: relative;
}

.drop-zone:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
    transform: scale(1.02);
}

.drop-zone-icon {
    font-size: 36px;
    margin-bottom: 8px;
}

.drop-zone-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.drop-zone-link {
    color: var(--accent);
    font-weight: 600;
    text-decoration: underline;
}

.drop-zone-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.drop-zone-input {
    display: none;
}