@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Clean Design Co Palette */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-card: #ffffff;
    --text-primary: #111827;
    /* Gray 900 */
    --text-secondary: #6b7280;
    /* Gray 500 */
    --border-color: #e5e7eb;
    /* Gray 200 */

    /* Branding Colors */
    --accent-primary: #111827;
    /* Black */
    --accent-hover: #374151;
    /* Gray 700 */
    --accent-secondary: #f3f4f6;
    /* Gray 100 */

    /* Functional Colors */
    --success: #059669;
    /* Emerald 600 */
    --success-bg: #d1fae5;
    --warning: #d97706;
    /* Amber 600 */
    --warning-bg: #fef3c7;
    --danger: #dc2626;
    /* Red 600 */
    --danger-bg: #fee2e2;

    /* Layout */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
}

.app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
}

/* --- Header --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-left: 12px;
    font-weight: 500;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* User Profile & Controls */
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-right: 16px;
    border-right: 1px solid var(--border-color);
    margin-right: 4px;
}

#userEmail {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.city-select {
    padding: 8px 32px 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    font-family: inherit;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
}

.city-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

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

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

.btn-secondary {
    background-color: white;
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--bg-secondary);
    border-color: #d1d5db;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.75rem;
}

/* --- Stats Bar --- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.stat-value {
    display: block;
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 4px;
    display: block;
}

.stat-card.highlight .stat-value {
    color: var(--accent-primary);
}

.stat-card.success .stat-value {
    color: var(--success);
}

/* --- Filters --- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.filter-group select,
.filter-group input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background-color: white;
    min-width: 160px;
}

.filter-group input {
    min-width: 240px;
}

/* --- Table --- */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

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

th {
    text-align: left;
    padding: 12px 24px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    cursor: pointer;
    /* Clickable */
    user-select: none;
    transition: background 0.2s;
}

th:hover {
    background-color: #f3f4f6;
    color: var(--text-primary);
}

th .sort-icon {
    margin-left: 5px;
    font-size: 0.7rem;
    opacity: 0.5;
}

th.sort-active .sort-icon {
    opacity: 1;
    color: var(--accent-primary);
}

td {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-primary);
    vertical-align: middle;
}

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

tr:hover {
    background-color: var(--bg-secondary);
}

.business-name {
    font-weight: 600;
    color: var(--text-primary);
}

.business-address {
    font-size: 0.75rem;
    color: var(--text-secondary);
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Badges */
.stage-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.stage-new {
    background-color: #eff6ff;
    color: #3b82f6;
}

/* Blue */
.stage-contacted {
    background-color: #fef3c7;
    color: #d97706;
}

/* Amber */
.stage-interested {
    background-color: #fee2e2;
    color: #dc2626;
}

/* Red */
.stage-proposal {
    background-color: #f3e8ff;
    color: #7c3aed;
}

/* Purple */
.stage-won {
    background-color: #d1fae5;
    color: #059669;
}

/* Green */
.stage-lost {
    background-color: #f3f4f6;
    color: #6b7280;
}

/* Gray */

.website-badge {
    display: inline-flex;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    margin-right: 8px;
}

.website-badge.has-website {
    background-color: var(--success-bg);
    color: var(--success);
}

.website-badge.no-website {
    background-color: var(--warning-bg);
    color: var(--warning);
}

.website-link {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-decoration: none;
}

.website-link:hover {
    color: var(--accent-primary);
    text-decoration: underline;
}

/* --- Modals (Login & Admin) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

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

.login-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 24px;
}

.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 10px;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.google-btn:hover {
    background-color: var(--bg-secondary);
    border-color: #d1d5db;
}

.google-btn img {
    width: 20px;
    height: 20px;
}

/* Admin Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1050;
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 600px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

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

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
    max-height: 70vh;
    overflow-y: auto;
}

.whitelist-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: var(--radius-md);
}

.whitelist-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.badge-admin {
    background: var(--text-primary);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

/* Detail Rows */
.detail-row {
    display: flex;
    margin-bottom: 16px;
    align-items: center;
}

.detail-row label {
    width: 120px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.detail-row span,
.detail-row a {
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
}

.detail-row.full-width {
    flex-direction: column;
    align-items: flex-start;
}

.detail-row.full-width label {
    margin-bottom: 8px;
}

textarea,
.detail-row select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.875rem;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    text-align: right;
    background: var(--bg-secondary);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

/* Side Panel */
.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 450px;
    height: 100vh;
    background: white;
    z-index: 1000;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.side-panel:not(.closed) {
    transform: translateX(0);
}

.panel-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
}

.panel-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.panel-title-group h2 {
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.panel-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.iframe-container {
    height: 250px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    margin-top: 8px;
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.iframe-placeholder {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    gap: 12px;
}

/* Utilities */
.hidden {
    display: none !important;
}

.text-danger {
    color: var(--danger);
}

/* Territory & Import Styles */
.full-width-input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-top: 5px;
}

.territory-checklist {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.territory-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}