* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1a202c;
    --text-muted: #718096;
    --primary: #3182ce;
    --success: #38a169;
    --danger: #e53e3e;
    --warning: #d69e2e;
    --info: #00b5d8;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header h1 { font-size: 20px; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 12px; }

.status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}
.status-badge.active { background: #c6f6d5; color: #22543d; }
.status-badge.inactive { background: #fed7d7; color: #742a2a; }

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
}
.tab {
    padding: 12px 20px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { color: var(--text); }
.badge {
    display: inline-block;
    background: var(--danger);
    color: white;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 6px;
}

/* Content */
.content { padding: 24px; }

/* Filters */
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.filter-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.filter-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.filter-btn:hover { border-color: var(--primary); }

/* Table */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: #f7fafc;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table td {
    padding: 10px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #f7fafc; }

.td-time { white-space: nowrap; color: var(--text-muted); font-size: 12px; }
.td-phone { font-family: monospace; font-weight: 600; }
.td-actions { white-space: nowrap; }

/* Row status colors */
.row-unique { background: #f0fff4; }
.row-duplicate { background: #fff5f5; }
.row-created { opacity: 0.6; }
.row-rejected { opacity: 0.5; }

/* Status badges */
.status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}
.status-new { background: #e2e8f0; }
.status-checking { background: #fefcbf; color: #744210; }
.status-unique { background: #c6f6d5; color: #22543d; }
.status-duplicate { background: #fed7d7; color: #742a2a; }
.status-created { background: #bee3f8; color: #2a4365; }
.status-rejected { background: #e2e8f0; color: #4a5568; }
.status-error { background: #fed7d7; color: #742a2a; }

/* Action badges */
.action-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}
.action-created_to_op { background: #c6f6d5; color: #22543d; }
.action-created_to_an { background: #b2f5ea; color: #234e52; }
.action-rejected { background: #fed7d7; color: #742a2a; }

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #2f855a; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c53030; }
.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #0987a0; }
.btn-warn { background: var(--warning); color: white; }
.btn-warn:hover { background: #b7791f; }
.btn-ghost { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: #f7fafc; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal {
    background: var(--surface);
    border-radius: 12px;
    padding: 28px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-wide {
    max-width: 650px;
}
.modal h2 { margin-bottom: 12px; font-size: 18px; }
.modal p { margin-bottom: 8px; font-size: 14px; }
.modal hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.form-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.form-group input {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}
.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(49,130,206,0.1);
}
.title-preview {
    margin-top: 12px;
    padding: 8px 12px;
    background: #f7fafc;
    border-radius: 6px;
    font-size: 13px;
    border: 1px solid var(--border);
}
.form-raw {
    margin-top: 10px;
}
.form-raw summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
}
.form-raw pre {
    margin-top: 6px;
    background: #f7fafc;
    padding: 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: pre-wrap;
    max-height: 100px;
    overflow-y: auto;
}

.checkbox-group, .radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
}
.checkbox-item, .radio-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
}
.checkbox-item input, .radio-item input {
    width: 16px;
    height: 16px;
}

.raw-text {
    background: #f7fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    margin: 12px 0;
}
.check-result {
    margin-top: 12px;
}
.check-result pre {
    background: #fff5f5;
    padding: 8px;
    border-radius: 4px;
    font-size: 12px;
    max-height: 150px;
    overflow-y: auto;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    text-align: center;
}
.stat-value { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.stats-breakdown {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.stats-breakdown h3 { margin-bottom: 12px; font-size: 15px; }
.stats-breakdown ul { list-style: none; }
.stats-breakdown li { padding: 6px 0; font-size: 14px; }

.empty {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Date filter */
.filter-sep { color: var(--border); margin: 0 8px; line-height: 32px; }
.date-filter {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-muted);
}
.date-filter input {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}

/* Deal links */
.deal-links {
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.deal-link {
    font-size: 11px;
    color: var(--primary);
    text-decoration: none;
    background: #ebf8ff;
    padding: 1px 6px;
    border-radius: 3px;
}
.deal-link:hover {
    background: #bee3f8;
    text-decoration: underline;
}

/* Raw messages debug tab */
.raw-info {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding: 8px 12px;
    background: #fffbeb;
    border-radius: 6px;
    border: 1px solid #fef3c7;
}
.raw-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    padding: 4px 8px;
}
.row-captured { background: #f0fff4; }
.row-skipped { background: #fff; opacity: 0.7; }
.td-mono { font-family: monospace; font-size: 11px; white-space: nowrap; }
.td-text { font-size: 12px; max-width: 400px; white-space: pre-wrap; word-break: break-word; }

/* Sortable table headers */
.sortable {
    cursor: pointer;
    user-select: none;
}
.sortable:hover {
    color: var(--primary);
}

/* Login screen */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f0f2f5;
}
.login-box {
    background: #fff;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
    text-align: center;
    width: 360px;
}
.login-box h1 {
    font-size: 1.4em;
    margin-bottom: 8px;
}
.login-box p {
    color: #666;
    margin-bottom: 20px;
}
.login-box input {
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
}
.login-box button {
    width: 100%;
    padding: 10px;
    margin-top: 4px;
}
.login-error {
    color: #e74c3c;
    margin-top: 10px;
    font-size: 13px;
}
