*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --radius: 10px;
}

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* Login */
.login-card { max-width: 360px; margin: 15vh auto; padding: 2.5rem; background: var(--surface); border-radius: var(--radius); box-shadow: 0 4px 24px rgba(0,0,0,.08); text-align: center; }
.login-card h1 { font-size: 2rem; margin-bottom: .25rem; }
.login-card .subtitle { color: var(--muted); margin-bottom: 1.5rem; }
.login-card form { display: flex; flex-direction: column; gap: .75rem; }
.login-card input { padding: .75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 1rem; outline: none; }
.login-card input:focus { border-color: var(--primary); }

/* Nav */
nav { display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.nav-brand { font-weight: 700; font-size: 1.1rem; margin-right: .5rem; white-space: nowrap; }
.nav-links { display: flex; gap: .25rem; flex: 1; }
.nav-link { padding: .4rem .9rem; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 500; transition: background .15s, color .15s; }
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: #eff6ff; color: var(--primary); }

/* Page */
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; gap: 1rem; flex-wrap: wrap; }
.page-header h2 { font-size: 1.35rem; }
.header-actions { display: flex; gap: .5rem; }

/* Buttons */
button { cursor: pointer; border: none; border-radius: 7px; font-size: .875rem; font-weight: 500; padding: .55rem 1.1rem; transition: background .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e0e7ff; color: var(--primary); }
.btn-secondary:hover { background: #c7d2fe; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

/* Cards */
.card-list { display: flex; flex-direction: column; gap: .75rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; }
.card-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.card-title { font-weight: 600; font-size: .95rem; }
.card-meta { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.card-actions { margin-left: auto; display: flex; gap: .4rem; }

/* Badge */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: #eff6ff; color: #1d4ed8; }

/* Forms */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .8rem; font-weight: 500; color: var(--muted); }
label input, label select, label textarea { padding: .55rem .75rem; border: 1px solid var(--border); border-radius: 7px; font-size: .9rem; color: var(--text); background: var(--surface); outline: none; }
label input:focus, label select:focus, label textarea:focus { border-color: var(--primary); }
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.form-row > label { flex: 1; min-width: 150px; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.form-details summary { cursor: pointer; font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 1rem; }
.modal.hidden { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 1.75rem; width: 100%; max-width: 580px; max-height: 90vh; overflow-y: auto; }
.modal-box h3 { margin-bottom: 1.25rem; }

/* Tabs */
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; }
.tab { padding: .4rem .9rem; border-radius: 6px; background: transparent; color: var(--muted); border: 1px solid var(--border); }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-pane textarea { width: 100%; border: 1px solid var(--border); border-radius: 7px; padding: .75rem; font-size: .85rem; font-family: monospace; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .5rem; }

/* NF preview */
.nf-preview { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: .75rem; font-size: .85rem; }
.nf-preview table { width: 100%; border-collapse: collapse; }
.nf-preview th, .nf-preview td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
.nf-preview th { color: var(--muted); font-weight: 600; font-size: .75rem; }

/* Filter tabs */
.filter-tabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.filter-btn { padding: .35rem .85rem; border-radius: 99px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); font-size: .8rem; }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Conversations */
.conversations-layout { display: flex; gap: 1rem; height: calc(100vh - 160px); }
.conv-sidebar { width: 280px; flex-shrink: 0; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; }
.conv-item { padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.conv-item:hover, .conv-item.active { border-color: var(--primary); background: #eff6ff; }
.conv-item .conv-phone { font-weight: 600; font-size: .9rem; }
.conv-item .conv-ts { color: var(--muted); font-size: .75rem; }
.conv-main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding: .5rem; }
.placeholder { color: var(--muted); text-align: center; margin-top: 3rem; }
.msg-bubble { max-width: 75%; padding: .6rem .9rem; border-radius: 12px; font-size: .875rem; line-height: 1.4; }
.msg-user { background: #e0e7ff; align-self: flex-start; }
.msg-assistant { background: #dcfce7; align-self: flex-end; }
.msg-ts { font-size: .7rem; color: var(--muted); margin-top: .15rem; }

/* Misc */
.loading { color: var(--muted); font-style: italic; padding: 1rem 0; }
.error { color: var(--danger); font-size: .85rem; }
.empty { color: var(--muted); text-align: center; padding: 2rem; }

/* Toast */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: #1e293b; color: #fff; padding: .7rem 1.4rem; border-radius: 99px; font-size: .9rem; z-index: 300; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.visible { opacity: 1; }
