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

:root {
    --ink: #2b2520;
    --ink-soft: #756b5f;
    --paper: #f3ede1;
    --panel: #fffdf9;
    --line: #e6dccb;
    --brand: #2d5d4f;
    --brand-dark: #1f4338;
    --brand-soft: #e6efe9;
    --clay: #c8693f;
    --clay-soft: #f6e4da;
    --clay-dark: #9c4a28;
    --warn: #b5532f;
    --warn-bg: #fbeae3;
    --ok: #2d5d4f;
    --ok-bg: #e6efe9;
    --radius: 14px;
    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* ---------- Login ---------- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at top, #2a4a3d 0%, #1a2e25 60%, #15241d 100%);
}
.login-box {
    background: var(--panel);
    padding: 40px 36px;
    border-radius: 20px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 30px 70px rgba(0,0,0,0.35);
}
.brand-mark {
    width: 44px;
    height: 44px;
    margin-bottom: 16px;
    display: block;
}
.login-box h1 {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 28px;
    margin: 0 0 4px;
    color: var(--ink);
}
.subtitle { color: var(--ink-soft); margin: 0 0 24px; font-size: 14px; }
.login-box label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin: 14px 0 6px;
    color: var(--ink-soft);
}
.login-box input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 15px;
    font-family: var(--font-body);
    background: var(--paper);
}
.login-box input:focus { outline: 2px solid var(--clay); outline-offset: 1px; background: var(--panel); }
.login-box button {
    width: 100%;
    margin-top: 22px;
    padding: 13px;
    background: var(--clay);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.login-box button:hover { background: var(--clay-dark); }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 8px; }
.alert-error { background: var(--warn-bg); color: var(--warn); }
.alert-success { background: var(--ok-bg); color: var(--ok); }

/* ---------- App shell ---------- */
.topbar {
    background: var(--brand-dark);
    color: white;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.topbar .brand {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 20px;
    letter-spacing: 0.2px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.topbar .brand img, .topbar .brand svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}
.topbar .who {
    font-size: 13px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 14px;
}
.topbar a {
    color: white;
    text-decoration: none;
    opacity: 0.85;
    font-size: 13px;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 5px 12px;
    border-radius: 8px;
}
.topbar a:hover { opacity: 1; background: rgba(255,255,255,0.08); }

.role-pill {
    background: rgba(255,255,255,0.15);
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.container {
    max-width: 880px;
    margin: 32px auto;
    padding: 0 20px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}
.panel h2 {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 19px;
    margin: 0 0 16px;
    color: var(--brand-dark);
}

/* ---------- Target selector ---------- */
.target-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.target-tab {
    padding: 9px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    transition: all 0.15s;
}
.target-tab.active {
    background: var(--brand);
    border-color: var(--brand);
    color: white;
}
.target-tab:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.node-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 8px;
}
.node-chip {
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    text-align: center;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    background: var(--paper);
    transition: all 0.15s;
}
.node-chip.selected {
    background: var(--brand);
    color: white;
    border-color: var(--brand);
}
.node-chip .status-dot {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    margin-right: 5px;
    background: #aab;
}
.node-chip .status-dot.online { background: #4caf6e; }

/* ---------- Recorder ---------- */
.recorder {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--paper);
    border-radius: var(--radius);
    border: 1px solid var(--line);
}
.rec-btn {
    width: 64px; height: 64px;
    border-radius: 50%;
    border: none;
    background: var(--clay);
    color: white;
    font-size: 22px;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.1s;
}
.rec-btn:hover { transform: scale(1.05); }
.rec-btn.recording {
    animation: pulse 1.2s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(200,105,63,0.5); }
    70% { box-shadow: 0 0 0 14px rgba(200,105,63,0); }
    100% { box-shadow: 0 0 0 0 rgba(200,105,63,0); }
}
.rec-info { flex: 1; }
.rec-timer { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec-status { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.rec-status.is-recording {color: var(--clay); font-weight: 600;}

audio { width: 100%; margin-top: 14px; }

.send-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
}
.send-summary { font-size: 13px; color: var(--ink-soft); }
.btn-send {
    padding: 12px 28px;
    background: var(--clay);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-send:hover { background: var(--clay-dark); }
.btn-send:disabled { background: #cdc2b3; cursor: not-allowed; }

/* ---------- History ---------- */
.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.history-table th {
    text-align: left;
    padding: 8px 10px;
    color: var(--ink-soft);
    font-weight: 600;
    border-bottom: 1px solid var(--line);
}
.history-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
}
.badge {
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.badge-sent { background: var(--ok-bg); color: var(--ok); }

/* ---------- Admin tables ---------- */
.btn-small {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    cursor: pointer;
    font-size: 12px;
}
.btn-small:hover { background: var(--paper); }
.form-row { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.form-row input, .form-row select {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--font-body);
}

@media (max-width: 600px) {
    .topbar { flex-direction: column; gap: 8px; align-items: flex-start; }
    .recorder { flex-direction: column; align-items: stretch; text-align: center; }
}
