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

:root {
    --green-dark: #1a1a1a;
    --green-mid: #2d6b27;
    --green-accent: #3a8f32;
    --gold: #c8961e;
    --gold-light: #fef3c7;
    --green-light: #e8f5e3;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --white: #ffffff;
    --red: #dc2626;
    --blue: #2563eb;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    font-size: 14px;
}

.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 220px;
    background: var(--green-dark);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 10;
    transition: width 0.2s ease;
    overflow: hidden;
}

.sidebar.collapsed { width: 56px; }

.logo {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
}

.logo-img { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }
.logo-text { white-space: nowrap; overflow: hidden; }
.logo h2 { font-size: 16px; font-weight: 700; color: var(--gold); margin: 0; }
.logo .subtitle { font-size: 11px; opacity: 0.6; }
.sidebar.collapsed .logo-text { opacity: 0; }

.sidebar-toggle {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 16px;
    padding: 8px 16px;
    cursor: pointer;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    transition: color 0.15s;
}

.sidebar-toggle:hover { color: var(--white); }
.sidebar.collapsed .sidebar-toggle { text-align: center; padding: 8px; }

.nav-links {
    list-style: none;
    padding: 8px 0;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-icon { flex-shrink: 0; width: 20px; display: flex; align-items: center; justify-content: center; opacity: 0.85; }
.nav-link:hover .nav-icon, .nav-link.active .nav-icon { opacity: 1; }
.nav-label { overflow: hidden; }
.sidebar.collapsed .nav-label { opacity: 0; width: 0; }

.nav-link:hover { background: rgba(255,255,255,0.08); color: var(--white); }
.nav-link.active { background: rgba(255,255,255,0.12); color: var(--white); font-weight: 600; }

.ai-status {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .ai-status .status-text { opacity: 0; width: 0; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-500);
    flex-shrink: 0;
}

.status-dot.online { background: #22c55e; }
.status-dot.offline { background: var(--red); }

/* Main content */
.content {
    flex: 1;
    margin-left: 220px;
    padding: 24px 32px;
    transition: margin-left 0.2s ease;
}

.sidebar.collapsed ~ .content { margin-left: 56px; }

/* Cards */
.card {
    background: var(--white);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    padding: 20px;
    margin-bottom: 16px;
}

.card h3 {
    font-size: 14px;
    color: var(--gray-500);
    font-weight: 500;
    margin-bottom: 8px;
}

.card .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
}

.card .card-detail {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 6px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

/* Page header */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--gray-900);
}

.page-header p {
    color: var(--gray-500);
    margin-top: 4px;
}

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

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

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

th {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--gray-50);
}

tr:hover td { background: var(--gray-50); }

.tier-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.tier-badge.gold { background: #fef3c7; color: #92400e; }
.tier-badge.silver { background: var(--gray-200); color: var(--gray-700); }
.tier-badge.bronze { background: #fed7aa; color: #9a3412; }
.tier-badge.standard { background: var(--green-light); color: var(--green-dark); }

/* Forms */
.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: flex-end;
}

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

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
}

input[type="text"], input[type="email"], select {
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

input[type="text"]:focus, input[type="email"]:focus, select:focus {
    border-color: var(--green-mid);
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-primary:hover:not(:disabled) { background: var(--green-mid); }

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) { background: var(--gray-300); }

.btn-danger {
    background: var(--red);
    color: var(--white);
}

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

/* Email preview */
.email-preview {
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    overflow: hidden;
    margin-top: 16px;
}

.email-preview-header {
    padding: 12px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-size: 13px;
}

.email-preview-header strong { color: var(--gray-700); }
.email-preview-header span { color: var(--gray-500); margin-left: 8px; }

.email-preview-body {
    padding: 0;
}

.email-preview-body iframe {
    width: 100%;
    min-height: 500px;
    border: none;
}

.email-actions {
    display: flex;
    gap: 12px;
    padding: 16px;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
}

/* Customer detail */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-item label {
    font-size: 12px;
    color: var(--gray-500);
    display: block;
    margin-bottom: 2px;
}

.detail-item .val {
    font-size: 15px;
    font-weight: 500;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    margin-top: 16px;
}

.pagination span { color: var(--gray-500); font-size: 13px; }

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--gray-500);
}

.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--green-dark);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Alert */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-error { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* Back link */
.back-link {
    color: var(--green-dark);
    text-decoration: none;
    font-size: 13px;
    display: inline-block;
    margin-bottom: 16px;
}

.back-link:hover { text-decoration: underline; }

/* Two column layout */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--white);
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

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

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

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

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

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-footer span { font-size: 13px; color: var(--gray-500); font-weight: 500; }

.modal-row { cursor: pointer; }
.modal-row:hover td { background: var(--green-light); }

.instr-item:hover { background: var(--gray-50); }
.instr-item.active { background: var(--green-light); border-left: 3px solid var(--green-mid); }

.modal-check {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--green-dark);
}

@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr) !important; }
}

@media (max-width: 900px) {
    .two-col { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .modal { width: 95%; max-height: 90vh; }
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
