/* The building blocks every page uses: cards, numbers, chips, buttons, fields, tables, messages, and the new
   simple-panel pieces (the "what needs you" tiles, settings tiles, list rows, an "advanced" fold). The Jinja side
   of the new pieces is app/templates/_ui.html. */

/* ---- surfaces ---- */
.grid { display:grid; gap:var(--s5); grid-template-columns:repeat(auto-fit, minmax(300px, 1fr)); }
.grid.two { grid-template-columns:repeat(auto-fit, minmax(min(460px, 100%), 1fr)); }
.grid.three { grid-template-columns:repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.grid.main-side { grid-template-columns:minmax(0, 1.45fr) minmax(0, 1fr); }
@media (max-width: 1023px) { .grid.main-side { grid-template-columns:1fr; } }
.card { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:22px 24px;
        box-shadow:var(--shadow); min-width:0; }
.card h2 { font-size:var(--t-md); margin:0 0 var(--s3); font-weight:700; display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.card h2 .sub { font-weight:400; color:var(--muted); font-size:var(--t-sm); }
.card h2 .more { margin-inline-start:auto; font-size:14px; font-weight:500; }
.card h2 > .ic:first-child { color:var(--accent); background:var(--accent-soft); border-radius:8px; padding:4px; width:28px; height:28px; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid, form + .card, .card + form, .todos + .card, .todos + .grid,
.status-line + .grid, .card + details.adv, .grid + details.adv { margin-top:var(--s5); }
@media (max-width: 640px) { .card { padding:18px 16px; } }

/* numbers */
.kpis { display:grid; gap:var(--s3); margin-bottom:var(--s4); grid-template-columns:repeat(auto-fit, minmax(128px, 1fr)); }
.kpi { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:var(--s3) var(--s4); box-shadow:var(--shadow); }
.kpi .label { color:var(--muted); font-size:var(--t-sm); display:flex; align-items:center; gap:6px; }
.kpi .label .ic { color:var(--accent); }
.kpi .value { font-size:26px; font-weight:700; font-variant-numeric:tabular-nums; line-height:1.4; }
.kpi.ok .value { color:var(--ok); } .kpi.bad .value { color:var(--bad); }
.figures { display:grid; gap:var(--s4); grid-template-columns:repeat(auto-fit, minmax(130px, 1fr)); }
.figure .l { color:var(--muted); font-size:14px; }
.figure .v { font-size:var(--t-xl); font-weight:700; line-height:1.3; font-variant-numeric:tabular-nums; }
.figure .d { font-size:var(--t-sm); color:var(--muted); }
.stats { display:flex; gap:var(--s5); flex-wrap:wrap; }
.stat { display:flex; flex-direction:column; } .stat span { color:var(--muted); font-size:var(--t-sm); } .stat b { font-size:20px; }

/* status chips: always a dot or text, never colour alone */
.pill { display:inline-flex; align-items:center; gap:6px; padding:1px 10px; border-radius:99px; font-size:var(--t-sm); font-weight:500;
        background:var(--surface-2); color:var(--ink-2); white-space:nowrap; line-height:1.8; border:1px solid transparent; }
.pill::before { content:""; width:7px; height:7px; border-radius:50%; background:currentColor; opacity:.7; }
.pill.ok { background:var(--ok-soft); color:var(--ok); } .pill.bad { background:var(--bad-soft); color:var(--bad); }
.pill.warn { background:var(--warn-soft); color:var(--warn); } .pill.info { background:var(--info-soft); color:var(--info); }
.pill.plain::before { display:none; }

/* ---- buttons: one main (violet), the rest quiet ---- */
button, .btn { display:inline-flex; align-items:center; gap:7px; background:var(--grad); color:var(--accent-ink); border:1px solid transparent;
               border-radius:12px; padding:7px 16px; min-height:40px; font:inherit; font-weight:600; cursor:pointer; text-decoration:none;
               box-shadow:0 6px 16px -10px rgba(109,40,217,.7); touch-action:manipulation;
               transition:transform .15s var(--ease), box-shadow .2s var(--ease), opacity .15s, border-color .15s, color .15s, background .15s; }
button:hover, .btn:hover { box-shadow:var(--glow); color:#fff; text-decoration:none; }
button:active, .btn:active { transform:scale(.97); box-shadow:none; }
button.secondary, .btn.secondary { background:var(--surface); color:var(--ink-2); border-color:var(--line-2); box-shadow:none; }
button.secondary:hover, .btn.secondary:hover { color:var(--accent); border-color:#c4b5fd; box-shadow:none; }
button.danger, .btn.danger { background:linear-gradient(135deg, #ef4444, #b91c1c); box-shadow:none; }
button.ghost, .btn.ghost { background:transparent; color:var(--accent); box-shadow:none; padding-inline:8px; }
button.ghost:hover, .btn.ghost:hover { background:var(--accent-soft); color:var(--accent); }
button.small, .btn.small { padding:3px 12px; min-height:34px; font-size:var(--t-sm); }
button:disabled, button[aria-busy="true"] { opacity:.55; cursor:not-allowed; transform:none; box-shadow:none; }
button[aria-busy="true"]::after { content:""; width:14px; height:14px; border:2px solid currentColor; border-top-color:transparent;
                                   border-radius:50%; animation:spin .7s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
.actions { display:flex; gap:var(--s2); flex-wrap:wrap; align-items:center; }
.toast button { background:transparent; border:0; color:#cbd5e1; min-height:24px; padding:0 4px; margin-inline-start:auto; box-shadow:none; }

/* ---- fields ---- */
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=time], input[type=datetime-local],
input[type=email], input[type=url], input[type=file], select, textarea {
  width:100%; padding:9px 12px; border:1px solid var(--line-2); border-radius:var(--radius-sm); font:inherit; background:#fff;
  color:var(--ink); min-height:42px; transition:border-color .15s, box-shadow .15s; }
input:hover, select:hover, textarea:hover { border-color:#c4b5fd; }
input:focus, select:focus, textarea:focus { outline:none; border-color:#8b5cf6; box-shadow:0 0 0 4px rgba(139,92,246,.16); }
input[type=file] { padding:6px; }
textarea { font-family:Consolas, "Courier New", monospace; font-size:var(--t-sm); direction:rtl; line-height:1.7; }
textarea.plain { font-family:inherit; font-size:var(--t-base); }
label { display:block; margin:var(--s4) 0 6px; color:var(--ink-2); font-size:14px; font-weight:500; }
.hint { color:var(--muted); font-size:var(--t-sm); margin-top:4px; }
label.check { display:inline-flex; gap:8px; align-items:center; margin:4px 0 4px 14px; font-weight:400; color:var(--ink); font-size:var(--t-base);
              min-height:36px; cursor:pointer; }
label.check input, input[type=checkbox], input[type=radio] { width:17px; height:17px; accent-color:var(--accent); }
fieldset { border:1px solid var(--line); border-radius:var(--radius-sm); padding:var(--s2) var(--s3) var(--s3); margin:var(--s3) 0 0; }
legend { padding:0 6px; font-size:var(--t-sm); font-weight:600; color:var(--ink-2); }
form.inline { display:flex; gap:var(--s2); align-items:center; flex-wrap:wrap; }
form.inline input, form.inline select { width:auto; flex:1 1 160px; }
.row { display:flex; gap:var(--s3); flex-wrap:wrap; } .row > * { flex:1 1 150px; min-width:0; }
.req::after { content:" *"; color:var(--bad); }
@media (max-width: 640px) { button, .btn { min-height:44px; } input, select { min-height:44px; } }

/* ---- tables ---- */
.table-wrap { overflow:auto; max-height:520px; border:1px solid var(--line); border-radius:12px; }
.table-wrap.tall { max-height:none; }
table { width:100%; border-collapse:collapse; font-size:14px; }
th, td { text-align:right; padding:10px 10px; border-bottom:1px solid var(--line); vertical-align:top; }
th { color:var(--muted); font-weight:500; font-size:var(--t-sm); background:var(--surface-3); position:sticky; top:0; z-index:1; white-space:nowrap; }
tbody tr:hover, table tr:hover td { background:var(--surface-3); }
tr:last-child td { border-bottom:0; }
td.wrap { max-width:380px; }
.scroll { overflow:auto; max-height:520px; }
.pager { margin-top:var(--s3); display:flex; gap:var(--s2); align-items:center; }

/* ---- messages ---- */
.toast { position:fixed; bottom:20px; left:20px; z-index:60; max-width:min(440px, calc(100vw - 40px)); display:flex; gap:10px; align-items:flex-start;
         background:rgba(27,24,64,.94); color:#fff; padding:12px 14px; border-radius:14px; box-shadow:0 18px 40px -10px rgba(30,27,75,.55);
         animation:rise .25s var(--ease); }
@keyframes rise { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
.alert { display:flex; gap:10px; align-items:flex-start; background:var(--bad-soft); border:1px solid #fecaca; color:#7f1d1d;
         padding:12px 16px; border-radius:12px; margin-bottom:var(--s4); }
.alert.warn { background:var(--warn-soft); border-color:#fde68a; color:#78350f; }
.alert.info { background:var(--info-soft); border-color:#bfdbfe; color:#1e3a8a; }
.empty { text-align:center; color:var(--muted); padding:var(--s5) var(--s3); }
.empty .ic { color:#c9bff0; display:block; margin:0 auto 8px; }
.empty b { display:block; color:var(--ink); font-size:var(--t-md); margin-bottom:2px; }
.empty .btn, .empty button { margin-top:var(--s3); }

/* the one-line state of the system, above the dashboard */
.status-line { display:flex; align-items:center; gap:10px; padding:12px 16px; border-radius:12px; font-weight:500;
               background:var(--ok-soft); color:var(--ok); }
.status-line.warn { background:var(--warn-soft); color:var(--warn); }
.status-line.bad { background:var(--bad-soft); color:var(--bad); }
.status-line .dot { width:9px; height:9px; border-radius:50%; background:currentColor; box-shadow:0 0 0 4px color-mix(in srgb, currentColor 15%, transparent); flex:none; }
.status-line a { margin-inline-start:auto; font-weight:600; color:inherit; text-decoration:underline; }

/* "what needs you": big tiles with a count */
.todos { display:grid; gap:var(--s4); grid-template-columns:repeat(auto-fit, minmax(min(200px, 100%), 1fr)); margin-top:var(--s5); }
.todo { display:flex; gap:14px; align-items:center; padding:18px 20px; border-radius:var(--radius); background:var(--surface);
        border:1px solid var(--line); box-shadow:var(--shadow); color:var(--ink); text-decoration:none;
        transition:transform .15s var(--ease), border-color .15s; }
.todo:hover { transform:translateY(-2px); border-color:#c9b8f7; color:var(--ink); }
.todo .ico { width:46px; height:46px; border-radius:14px; display:grid; place-items:center; background:var(--accent-soft); color:var(--accent); flex:none; }
.todo b { font-size:26px; line-height:1.1; display:block; font-variant-numeric:tabular-nums; }
.todo span { color:var(--muted); font-size:14px; }
.todo.zero b { color:var(--muted); }

/* settings home: a tile per settings page */
.tile { display:block; padding:20px; border-radius:var(--radius); background:var(--surface); border:1px solid var(--line); box-shadow:var(--shadow);
        color:var(--ink); text-decoration:none; transition:transform .15s var(--ease), border-color .15s; }
.tile:hover { transform:translateY(-2px); border-color:#c9b8f7; color:var(--ink); }
.tile .ico { width:44px; height:44px; border-radius:13px; display:grid; place-items:center; background:var(--accent-soft); color:var(--accent); margin-bottom:12px; }
.tile b { display:block; font-size:var(--t-md); }
.tile span { color:var(--muted); font-size:14px; }
.tile em { display:block; font-style:normal; font-size:var(--t-sm); margin-top:10px; }

/* simple list rows (instead of wide tables) */
.rows { display:flex; flex-direction:column; }
.rows .r { display:flex; align-items:center; gap:14px; padding:14px 0; border-top:1px solid var(--line); min-width:0; }
.rows .r:first-child { border-top:0; padding-top:4px; }
.rows .grow { flex:1; min-width:0; }
.rows .t { font-weight:600; color:var(--ink); display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.rows a.t:hover { color:var(--accent); }
.rows .s { color:var(--muted); font-size:var(--t-sm); }
.rows form { margin:0; }
@media (max-width: 640px) { .rows .hide-m { display:none; } }

/* progress */
.bar { height:6px; background:var(--surface-2); border-radius:6px; overflow:hidden; min-width:60px; width:120px; }
.bar i { display:block; height:100%; background:var(--grad); border-radius:6px; }

/* "advanced": technical things, folded */
details summary { cursor:pointer; color:var(--accent); }
details.adv { border:1px dashed var(--line-2); border-radius:var(--radius); padding:14px 20px; background:rgba(255,255,255,.6); }
details.adv > summary { font-weight:600; color:var(--ink-2); list-style:none; display:flex; align-items:center; gap:8px; min-height:28px; }
details.adv > summary::-webkit-details-marker { display:none; }
details.adv > summary::after { content:"▾"; margin-inline-start:auto; color:var(--muted); transition:transform .15s; }
details.adv[open] > summary::after { transform:rotate(180deg); }
details.adv[open] > summary { margin-bottom:var(--s3); }
details.help { display:inline-block; }
details.help > summary { list-style:none; font-size:var(--t-sm); }
details.help > summary::-webkit-details-marker { display:none; }
details.help[open] p { background:var(--surface-3); border:1px solid var(--line); border-radius:12px; padding:10px 14px; margin:8px 0 0;
                       color:var(--ink-2); font-size:14px; max-width:720px; }

/* in-page tabs (a campaign: overview, contacts, behaviour, advanced) */
.page-tabs { display:flex; gap:4px; border-bottom:1px solid var(--line); margin:0 0 var(--s5); overflow-x:auto; scrollbar-width:none; }
.page-tabs a { padding:9px 14px; font-weight:500; color:var(--muted); border-bottom:2px solid transparent; white-space:nowrap; min-height:44px;
               display:inline-flex; align-items:center; text-decoration:none; }
.page-tabs a[aria-current="page"] { color:var(--accent); border-bottom-color:var(--accent); }

/* live lines and transcripts */
.lines { display:grid; gap:var(--s3); grid-template-columns:repeat(auto-fit, minmax(290px, 1fr)); }
.line { border:1px solid var(--line); border-radius:var(--radius-sm); padding:var(--s3); background:var(--surface-3); }
.line header { display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-bottom:6px; }
.live-line { padding:3px 0; border-bottom:1px dashed var(--line); font-size:14px; }
.live-line .who { font-weight:600; margin-left:6px; color:var(--ink-2); }
.bubble { padding:8px 12px; border-radius:12px; margin:6px 0; max-width:82%; line-height:1.8; }
.bubble.bot { background:var(--accent-soft); margin-left:auto; border-bottom-left-radius:4px; }
.bubble.customer { background:var(--surface-2); margin-right:auto; border-bottom-right-radius:4px; }
.bubble.event, .bubble.sms { background:none; color:var(--muted); font-size:var(--t-sm); text-align:center; max-width:100%; }

/* clickable cards on other pages lift a little */
a.wf-item, .wf-item, a.cn-item, .tpl { transition:transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s; }
a.wf-item:hover, .wf-item:hover, a.cn-item:hover, .tpl:hover { transform:translateY(-2px); box-shadow:var(--shadow-lg); border-color:rgba(124,58,237,.35); }
@media (prefers-reduced-motion: reduce) {
  .todo:hover, .tile:hover, a.wf-item:hover, .wf-item:hover, a.cn-item:hover, .tpl:hover { transform:none !important; }
}

/* a "⋯" menu for the less used actions of a page */
details.menu { position:relative; }
details.menu > summary { list-style:none; min-width:42px; justify-content:center; font-size:18px; line-height:1; }
details.menu > summary::-webkit-details-marker { display:none; }
details.menu .menu-list { position:absolute; inset-inline-end:0; top:calc(100% + 6px); z-index:30; min-width:220px; background:var(--surface);
                          border:1px solid var(--line); border-radius:14px; box-shadow:var(--shadow-lg); padding:6px; display:flex; flex-direction:column; }
details.menu .menu-list a { display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:10px; color:var(--ink); text-decoration:none; }
details.menu .menu-list a:hover { background:var(--accent-soft); color:var(--accent); }

/* phone: the "waiting for you" tiles side by side, compact */
@media (max-width: 640px) {
  .todos { grid-template-columns:repeat(3, minmax(0, 1fr)); gap:8px; margin-top:var(--s4); }
  .todo { flex-direction:column; align-items:flex-start; gap:6px; padding:12px; }
  .todo .ico { width:34px; height:34px; border-radius:11px; }
  .todo b { font-size:22px; }
  .todo span { font-size:var(--t-xs); line-height:1.5; }
}

/* phase 2: rows with more than one line, coloured figures, a choice of kind (channels), short key-value lists */
.rows .s { display:block; }
.rows .s.bad { color:var(--bad); }
.figure .v.ok { color:var(--ok); }
.kv { display:grid; grid-template-columns:max-content 1fr; gap:8px 18px; margin:0; }
.kv dt { color:var(--muted); font-size:14px; } .kv dd { margin:0; }
.choice { display:grid; gap:var(--s3); grid-template-columns:repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.choice label { margin:0; display:flex; gap:12px; align-items:center; padding:14px 16px; border:1px solid var(--line-2); border-radius:var(--radius-sm);
  cursor:pointer; background:var(--surface); min-height:56px; }
.choice label:has(input:checked) { border-color:var(--accent); background:var(--accent-soft); color:var(--accent); }
.choice input { position:absolute; opacity:0; pointer-events:none; }
.choice label:focus-within { outline:2px solid var(--accent); outline-offset:2px; }
.page-tabs .badge { margin-inline-start:6px; }
/* the dashboard's «الان در جریان»: what is going on right now, each a link to its live view */
.now-row { display:flex; gap:var(--s3); flex-wrap:wrap; }
.now-item { display:inline-flex; align-items:center; gap:8px; padding:10px 16px; border-radius:12px; border:1px solid var(--line);
  background:var(--surface-3); color:var(--ink-2); min-height:44px; }
.now-item:hover { border-color:#c9b8f7; color:var(--accent); text-decoration:none; }
.now-item .ico { color:var(--accent); display:inline-flex; }
.now-item b { font-size:18px; color:var(--ink); font-variant-numeric:tabular-nums; }
#lines:not(:empty) { margin-top:var(--s4); }
[hidden] { display:none !important; }
