/*
 * TG Bridge panel — one stylesheet, no build step, no external fonts.
 *
 * No webfont on purpose: the bridge is deployed outside Iran and read from
 * inside it, and a Google Fonts request is one more thing that can be blocked
 * or slow. The system stack renders Persian correctly on every platform this
 * panel is opened from.
 */

:root {
    color-scheme: light dark;

    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --border: #dfe3e8;
    --text: #1b1f24;
    --text-dim: #61686f;
    --accent: #1f6feb;
    --accent-soft: #e8f0fe;
    --ok: #1a7f37;
    --ok-soft: #e7f6ea;
    --bad: #b91c1c;
    --bad-soft: #fdeceb;
    --wait: #9a6700;
    --wait-soft: #fdf5e2;
    --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
    --radius: 10px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117;
        --surface: #161b22;
        --surface-2: #1c2129;
        --border: #2b323c;
        --text: #e6edf3;
        --text-dim: #93a1b1;
        --accent: #58a6ff;
        --accent-soft: #16283f;
        --ok: #4ac26b;
        --ok-soft: #10281a;
        --bad: #ff7b72;
        --bad-soft: #2d1618;
        --wait: #e3b341;
        --wait-soft: #2a2113;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, system-ui, -apple-system, "Noto Sans Arabic", sans-serif;
    font-size: 14px;
    line-height: 1.75;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- chrome */

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.6rem 1.2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; }
.brand-lg { font-size: 1.2rem; justify-content: center; margin-bottom: 1.2rem; }
.logo { font-size: 1.3rem; }
.version { font-size: 0.72rem; color: var(--text-dim); font-weight: 400; font-family: var(--mono); }

.mainnav { display: flex; gap: 0.25rem; flex-wrap: wrap; flex: 1; }
.mainnav a {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    color: var(--text-dim);
}
.mainnav a:hover { background: var(--surface-2); text-decoration: none; }
.mainnav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }

/* ---------------------------------------------------------------- blocks */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1.1rem;
}

.card > h2, .card > h3 { margin: 0 0 0.8rem; font-size: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.card-head h2 { margin: 0; font-size: 1rem; }

h1 { font-size: 1.35rem; margin: 0 0 1rem; }
.sub { color: var(--text-dim); margin: -0.6rem 0 1.2rem; }

.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* stat tiles */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; }
.stat .label { color: var(--text-dim); font-size: 0.8rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--text-dim); font-size: 0.78rem; }
.stat.stat-ok { border-inline-start: 3px solid var(--ok); }
.stat.stat-bad { border-inline-start: 3px solid var(--bad); }
.stat.stat-wait { border-inline-start: 3px solid var(--wait); }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.5rem 0.6rem; text-align: right; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-dim); font-weight: 600; font-size: 0.8rem; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono { font-family: var(--mono); font-size: 0.82rem; direction: ltr; text-align: left; }
.empty { padding: 2rem; text-align: center; color: var(--text-dim); }

/* ---------------------------------------------------------------- pieces */

.badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.76rem;
    white-space: nowrap;
    font-weight: 600;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-wait { background: var(--wait-soft); color: var(--wait); }
.badge-mute { background: var(--surface-2); color: var(--text-dim); }

.muted { color: var(--text-dim); }
.ts { border-bottom: 1px dotted var(--border); cursor: help; }

.banner { border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 1rem; border: 1px solid transparent; }
.banner ul { margin: 0.4rem 0 0; padding-inline-start: 1.2rem; }
.banner-ok { background: var(--ok-soft); border-color: var(--ok); }
.banner-bad { background: var(--bad-soft); border-color: var(--bad); }
.banner-info { background: var(--accent-soft); border-color: var(--accent); }

/* ---------------------------------------------------------------- forms */

label { display: block; margin-bottom: 0.9rem; }
label > span { display: block; margin-bottom: 0.25rem; color: var(--text-dim); font-size: 0.85rem; }
label > small { display: block; color: var(--text-dim); font-size: 0.78rem; margin-top: 0.2rem; }

input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 8rem; font-family: var(--mono); direction: ltr; text-align: left; font-size: 0.85rem; }
input.ltr { direction: ltr; text-align: left; font-family: var(--mono); }

.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 140px; }
.row > .narrow { flex: 0 0 auto; min-width: 0; }

.checkline { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.9rem; }
.checkline input { width: auto; }
.checkline span { margin: 0; }

.btn {
    display: inline-block;
    padding: 0.42rem 0.9rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 0.2rem 0.55rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }

/* ---------------------------------------------------------------- code */

.codeblock { position: relative; margin: 0 0 0.8rem; }
.codeblock pre {
    margin: 0;
    padding: 0.7rem 0.8rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 26rem;
}
.codeblock.secret pre { border-color: var(--wait); background: var(--wait-soft); }
.codeblock .copy {
    position: absolute;
    inset-inline-start: 0.4rem;
    top: 0.4rem;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-dim);
    cursor: pointer;
}
.codeblock .copy:hover { color: var(--accent); border-color: var(--accent); }

/* ---------------------------------------------------------------- misc */

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0; }
dl.kv dt { color: var(--text-dim); }
dl.kv dd { margin: 0; word-break: break-word; }
dl.kv dd.mono { font-family: var(--mono); direction: ltr; text-align: left; font-size: 0.82rem; }

.pager { display: flex; gap: 0.4rem; justify-content: center; margin-top: 1rem; align-items: center; }
.page { padding: 0.25rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; }
.page.current { border: none; color: var(--text-dim); }
.page.disabled { opacity: 0.4; }

.check-row { display: flex; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.check-row:last-child { border-bottom: none; }
.check-row .body { flex: 1; }
.check-row .hint { color: var(--text-dim); font-size: 0.85rem; }

.log-line { display: grid; grid-template-columns: 5.5rem 4.5rem 7rem 1fr; gap: 0.6rem; padding: 0.3rem 0; border-bottom: 1px solid var(--border); font-size: 0.84rem; }
.log-line:last-child { border-bottom: none; }
.log-line .lvl { font-weight: 700; font-size: 0.76rem; }
.log-line .lvl.error { color: var(--bad); }
.log-line .lvl.warning { color: var(--wait); }
.log-line .lvl.info { color: var(--ok); }
.log-line .lvl.debug { color: var(--text-dim); }
.log-line .ctx { font-family: var(--mono); font-size: 0.78rem; direction: ltr; text-align: left; color: var(--text-dim); word-break: break-all; }
.log-line .chan { color: var(--text-dim); font-family: var(--mono); font-size: 0.78rem; }

.centered { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(380px, 100%); }

.tag { font-family: var(--mono); font-size: 0.8rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 0.05rem 0.35rem; direction: ltr; display: inline-block; }

.split { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

@media (max-width: 720px) {
    .log-line { grid-template-columns: 1fr; gap: 0.15rem; }
    .topbar { padding: 0.6rem; }
    main { padding: 0.75rem; }
}
