/*
 * AiServe SmartTag — admin styles (section 48).
 * Modern, minimal SaaS chrome. No framework, no web fonts, mobile friendly.
 */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --sidebar: #111826;
    --sidebar-text: #aab4c4;
    --sidebar-active: #ffffff;
    --text: #101828;
    --muted: #667085;
    --border: #e4e7ec;
    --primary: #0d6efd;
    --danger: #d92d20;
    --ok: #12875a;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--bg); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.tiny { font-size: .8rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.break { overflow-wrap: anywhere; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 8px; top: 8px; background: #fff; padding: 8px 12px; z-index: 100; border-radius: 8px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px; flex: 0 0 232px; background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; }
.brand-mark {
    width: 32px; height: 32px; border-radius: 9px; background: var(--primary);
    display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .82rem;
}
.brand-text { font-weight: 650; font-size: .95rem; }
.brand-lg { justify-content: center; color: var(--text); margin-bottom: 4px; }

.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 1px; flex: 1; }
.nav-item { color: var(--sidebar-text); padding: 9px 12px; border-radius: 9px; font-size: .9rem; }
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-item.is-active { background: rgba(255, 255, 255, .1); color: var(--sidebar-active); font-weight: 600; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255, 255, 255, .08); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 14px; padding: 13px 22px;
    background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 1.08rem; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; flex-direction: column; line-height: 1.2; text-align: right; font-size: .82rem; }
.user-chip .role { color: var(--muted); font-size: .74rem; }
.burger { display: none; background: none; border: 0; font-size: 1.25rem; cursor: pointer; color: var(--text); }
.inline { display: inline; }

.main { padding: 22px; flex: 1; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 15px; border: 1px solid var(--border); border-radius: 9px;
    background: var(--surface); color: var(--text); font-size: .88rem; font-weight: 550;
    cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #0b5ed7; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b42318; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 12px; font-size: .83rem; }
.btn-xs { padding: 4px 9px; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- panels & cards ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 12px; }
.panel-head h2 { font-size: .95rem; margin: 0; }
.panel-head p { margin: 0; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.panel-grid .panel + .panel { margin-top: 0; }
.panel-wide { grid-column: 1 / -1; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { margin: 0 0 4px; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { margin: 0; font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
.table th a { color: inherit; }
.table tbody tr:hover { background: #fbfcfd; }
.table-compact th, .table-compact td { padding: 7px 10px; }
.row-actions { white-space: nowrap; display: flex; gap: 6px; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; font-size: .9rem; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: .76rem; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.badge-active { background: #e7f7ef; color: var(--ok); }
.badge-inactive, .badge-suspended { background: #fef0c7; color: #b54708; }
.badge-lost, .badge-damaged, .badge-discontinued { background: #fee4e2; color: var(--danger); }
.badge-replaced, .badge-archived, .badge-completed { background: #eef1f5; color: var(--muted); }

/* ---------- toolbar & filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input, .filters select {
    padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px; font-size: .86rem;
    background: var(--surface); color: var(--text); min-height: 38px;
}
.range-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.range { padding: 7px 13px; border-radius: 9px; font-size: .85rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.range.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.range:hover { text-decoration: none; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.form-wide { gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; align-items: start; }
.form label { display: grid; gap: 5px; font-size: .84rem; color: var(--muted); font-weight: 550; }
.form input[type=text], .form input[type=email], .form input[type=tel], .form input[type=url],
.form input[type=password], .form input[type=number], .form input[type=date], .form input[type=search],
.form select, .form textarea {
    width: 100%; padding: 9px 12px; font-size: .92rem; color: var(--text);
    border: 1px solid var(--border); border-radius: 9px; background: var(--surface); min-height: 40px;
}
.form textarea { min-height: 84px; resize: vertical; font-family: inherit; }
.form input[readonly] { background: var(--bg); color: var(--muted); }
.form .hint { font-weight: 400; color: var(--muted); font-size: .78rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { border: 1px solid var(--border); border-radius: 9px; padding: 12px; display: grid; gap: 8px; }
.choice legend { font-size: .8rem; color: var(--muted); padding: 0 4px; }
.radio { display: flex !important; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
.radio input { width: 17px; height: 17px; min-height: 0; }
.form-foot { display: flex; gap: 10px; align-items: center; padding-top: 4px; }
.preview { border-radius: 9px; border: 1px solid var(--border); margin-top: 6px; }
.sub { font-size: .84rem; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); font-size: .85rem; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 10px; flex-wrap: wrap; }
.inline-form select, .inline-form input { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; }

.danger-zone { border-color: #fda29b; }
.danger-zone .panel-head h2 { color: var(--danger); }

/* ---------- detail pages ---------- */
.detail-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.detail-title { margin: 0 0 2px; font-size: 1.2rem; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.kv { margin: 0; display: grid; gap: 1px; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.kv dt { color: var(--muted); font-size: .82rem; margin: 0; }
.kv dd { margin: 0; text-align: right; font-size: .88rem; }
.qr-preview { border: 1px solid var(--border); border-radius: 9px; background: #fff; }

/* ---------- action builder ---------- */
.action-list { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 8px; }
.action-item {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; background: var(--surface);
}
.action-item.dragging { opacity: .5; }
.drag { cursor: grab; color: var(--muted); user-select: none; }
.action-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; flex: 1; }
.action-form input, .action-form select { padding: 6px 9px; border: 1px solid var(--border); border-radius: 7px; font-size: .82rem; }
.action-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; border-top: 1px solid var(--border); padding-top: 14px; }
.action-add input, .action-add select { padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; }

/* ---------- funnel ---------- */
.funnel { list-style: none; padding: 0; margin: 0; display: grid; gap: 9px; }
.funnel-row { display: grid; grid-template-columns: 110px 1fr 100px; gap: 10px; align-items: center; font-size: .84rem; }
.funnel-bar { background: var(--bg); border-radius: 999px; height: 9px; overflow: hidden; }
.funnel-bar span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.funnel-value { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- misc ---------- */
.alert { padding: 11px 14px; border-radius: 9px; margin-bottom: 14px; font-size: .88rem; }
.alert-success { background: #e7f7ef; color: var(--ok); }
.alert-error { background: #fee4e2; color: var(--danger); }
.alert-warning { background: #fef0c7; color: #b54708; }
.alert-info { background: #eff8ff; color: #175cd3; }
.summary { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 18px; font-size: .9rem; }
.errors { font-size: .82rem; color: var(--danger); }
/* An explicit height keeps the panel the right size before charts.js runs — a canvas
   with only a width set would otherwise scale to its intrinsic aspect ratio. */
.chart { width: 100%; max-width: 100%; display: block; height: 200px; }
.avatar-xs { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; }
.avatar-xs.avatar-initials { background: var(--primary); color: #fff; font-size: .74rem; font-weight: 700; }
.pagination { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.page { padding: 6px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: .84rem; }
.page.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-gap { color: var(--muted); padding: 0 2px; }

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 390px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); text-align: center; }
.login-card .form { margin-top: 16px; text-align: left; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .18s ease; }
    .sidebar.is-open { transform: translateX(0); }
    .burger { display: block; }
    .two-col { grid-template-columns: 1fr; }
    .main { padding: 16px; }
    .table th, .table td { padding: 8px 10px; }
    .panel-flush { overflow-x: auto; }
    .funnel-row { grid-template-columns: 90px 1fr 84px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
