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

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

:root {
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --border-focus: #6366f1;
    --text: #0f172a;
    --text-secondary: #64748b;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --participant: #3b82f6;
    --participant-light: #dbeafe;
    --candidate: #f59e0b;
    --candidate-light: #fef3c7;
    --selected: #6366f1;
    --danger: #ef4444;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.05);
    --transition: 150ms cubic-bezier(.4,0,.2,1);
}

body {
    font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
header {
    background: var(--text);
    color: #fff;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

header .logo {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
}

header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.3px;
}

header p {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 1px;
}

/* ===== Layout ===== */
.container {
    display: flex;
    height: calc(100vh - 64px);
}

.panel {
    width: 400px;
    min-width: 360px;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg);
}

.panel::-webkit-scrollbar { width: 4px; }
.panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

#map {
    flex: 1;
    min-height: 300px;
    border-left: 1px solid var(--border);
}

/* ===== Cards ===== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.card-header .icon {
    width: 28px; height: 28px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.card-header .icon.blue { background: var(--participant-light); }
.card-header .icon.amber { background: var(--candidate-light); }
.card-header .icon.purple { background: #ede9fe; }

.card-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

/* ===== Inputs ===== */
input[type="text"], select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: var(--card);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]:focus, select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

/* ===== Participant Table ===== */
#participant-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
}

#participant-table th {
    padding: 0 8px 6px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
}

#participant-table td {
    padding: 3px 4px;
}

#participant-table input {
    padding: 7px 10px;
    font-size: 13px;
}

.addr-cell {
    display: flex;
    align-items: center;
    gap: 6px;
}
.addr-cell input { flex: 1; }

.addr-status {
    font-size: 13px;
    font-weight: 700;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    transition: color var(--transition);
}
.addr-ok { color: var(--participant); }
.addr-err { color: var(--danger); cursor: help; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    font-size: 14px;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: #a5b4fc; cursor: wait; }

.btn-secondary {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: #e2e8f0; color: var(--text); }
.btn-secondary:disabled { opacity: .5; cursor: wait; }

.btn-accent {
    background: var(--participant);
    color: #fff;
}
.btn-accent:hover { background: #2563eb; }
.btn-accent:disabled { background: #93c5fd; cursor: wait; }

.btn-icon {
    background: none;
    border: none;
    font-size: 16px;
    color: #cbd5e1;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all var(--transition);
}
.btn-icon:hover { color: var(--danger); background: #fef2f2; }

.btn-row {
    display: flex;
    gap: 8px;
}

/* ===== Candidate Input ===== */
.candidate-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}
.candidate-input-row input { flex: 1; }

/* ===== Tags ===== */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 8px;
}

.tag {
    background: var(--candidate-light);
    color: #92400e;
    border: 1px solid #fcd34d;
    border-radius: 20px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all var(--transition);
}

.tag button {
    background: none;
    border: none;
    cursor: pointer;
    color: #d97706;
    font-size: 13px;
    line-height: 1;
    padding: 0;
    transition: color var(--transition);
}
.tag button:hover { color: var(--danger); }

.tag-error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fca5a5;
}
.tag-error button { color: #f87171; }
.tag-err-msg { font-size: 11px; opacity: .7; }

/* ===== Result ===== */
#result-section { animation: fadeIn .3s ease; }

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

#result-message {
    background: linear-gradient(135deg, #ede9fe, #e0e7ff);
    border: 1px solid #c7d2fe;
    border-radius: 10px;
    padding: 14px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.6;
    white-space: pre-line;
    margin-bottom: 10px;
    color: #3730a3;
}

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

#result-table th {
    padding: 6px 10px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 2px solid var(--border);
}

#result-table td {
    padding: 8px 10px;
    font-size: 13px;
    border-bottom: 1px solid #f1f5f9;
}

#result-table tr:last-child td { border: none; }

/* ===== Legend ===== */
.legend {
    display: flex;
    gap: 14px;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 8px;
    margin-top: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .container {
        flex-direction: column-reverse;
        height: auto;
        min-height: calc(100vh - 56px);
    }

    header { padding: 12px 16px; }
    header h1 { font-size: 16px; }

    .panel {
        width: 100%;
        min-width: 0;
        padding: 12px;
        gap: 10px;
    }

    #map {
        height: 40vh;
        min-height: 200px;
        position: sticky;
        top: 0;
        z-index: 10;
        border-left: none;
        border-bottom: 1px solid var(--border);
    }

    .card { padding: 14px; }

    /* Prevent iOS auto-zoom on input focus */
    input[type="text"], select {
        font-size: 16px;
        padding: 10px 12px;
    }

    #participant-table input {
        font-size: 16px;
        padding: 9px 10px;
    }

    /* Larger touch targets */
    .btn {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
    }

    .btn-primary {
        padding: 12px;
        font-size: 15px;
    }

    .btn-icon {
        font-size: 20px;
        padding: 6px 8px;
        min-width: 36px;
        min-height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .tag {
        padding: 6px 12px;
        font-size: 13px;
    }

    .tag button {
        font-size: 16px;
        padding: 0 4px;
    }

    .legend {
        justify-content: center;
    }

    /* Table: stack name above address on very narrow screens */
    #participant-table th:last-child,
    #participant-table td:last-child {
        width: 36px;
        text-align: center;
    }
}

@media (max-width: 380px) {
    .btn-row { flex-direction: column; }
    .btn-row .btn { width: 100%; }
}
