/* pr2/assets/css/app.css — ThaiFriendly Affiliate centre, dark theme.
   No framework. CSS custom properties + Grid/Flexbox. */

:root {
    color-scheme: dark;

    /* Surfaces */
    --bg:            #0e1117;
    --surface-1:     #161b22;
    --surface-2:     #1f2632;
    --surface-3:     #2a3342;
    --border:        #2d3542;
    --border-strong: #3d4759;

    /* Text */
    --text:       #e6e9ef;
    --text-muted: #9aa4b2;
    --text-faint: #6b7585;

    /* Brand */
    --tf:        #0078ff;
    --tf-accent: #546aff;
    --tf-soft:   rgba(84, 106, 255, .14);
    --pl:        #ff8600;
    --pl-accent: #ffb020;
    --pl-soft:   rgba(255, 176, 32, .14);

    /* Semantic */
    --success:      #2ea043;
    --success-soft: rgba(46, 160, 67, .15);
    --danger:       #e5534b;
    --danger-soft:  rgba(229, 83, 75, .15);
    --warning:      #d29922;
    --warning-soft: rgba(210, 153, 34, .15);
    --info:         #539bf5;
    --info-soft:    rgba(83, 155, 245, .15);

    /* Scale */
    --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
    --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;
    --r-sm: 6px; --r-md: 10px; --r-lg: 16px; --r-pill: 999px;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 8px 28px rgba(0, 0, 0, .5);

    --container: 1080px;
    --nav-h: 60px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    padding-top: var(--nav-h);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--tf-accent); }
a:hover { color: #7e8fff; }

h1, h2, h3, h4 { line-height: 1.25; font-weight: 650; }
h1 { font-size: 28px; margin: 0 0 var(--s-4); }
h2 { font-size: 20px; margin: var(--s-5) 0 var(--s-3); }
h3 { font-size: 16px; margin: 0 0 var(--s-3); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-6) 0; }
b, strong { font-weight: 650; }
code { font-family: var(--font-mono); }

:focus-visible {
    outline: 2px solid var(--tf-accent);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    left: -999px;
    top: var(--s-2);
    background: var(--surface-2);
    padding: var(--s-2) var(--s-4);
    border-radius: var(--r-sm);
    z-index: 200;
}
.skip-link:focus { left: var(--s-3); }

/* ----------------------------------------------------------- containers */

.container {
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--s-4);
}
main.container { padding-block: var(--s-6); min-height: 60vh; }
.footer { color: var(--text-faint); padding-bottom: var(--s-6); }

/* ----------------------------------------------------------------- nav */

.nav {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}
.nav__inner {
    max-width: var(--container);
    margin-inline: auto;
    height: 100%;
    padding-inline: var(--s-4);
    display: flex;
    align-items: center;
    gap: var(--s-4);
}
.nav__brand {
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.nav__menu {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-left: auto;
}
.nav__menu a {
    color: var(--text-muted);
    text-decoration: none;
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-sm);
    white-space: nowrap;
}
.nav__menu a:hover { color: var(--text); background: var(--surface-2); }
.nav__signin { color: var(--text-muted); }
.nav__signin strong { color: var(--tf-accent); }

.nav__user { position: relative; }
.nav__userbtn {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: var(--s-2) var(--s-3);
    font: inherit;
    cursor: pointer;
}
.nav__userbtn:hover { border-color: var(--border-strong); }
.nav__dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 170px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
    padding: var(--s-1);
    display: none;
}
.nav__dropdown.is-open { display: block; }
.nav__dropdown a { display: block; }

.nav__toggle {
    display: none;
    margin-left: auto;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: 0;
    cursor: pointer;
    padding: var(--s-2);
}
.nav__toggle span {
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
}

@media (max-width: 720px) {
    .nav__toggle { display: flex; }
    .nav__menu {
        position: fixed;
        top: var(--nav-h);
        left: 0; right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        background: var(--surface-1);
        border-bottom: 1px solid var(--border);
        padding: var(--s-2);
        display: none;
    }
    .nav__menu.is-open { display: flex; }
    .nav__menu--guest { display: flex; }
    .nav__user { position: static; }
    .nav__userbtn { width: 100%; justify-content: space-between; }
    .nav__dropdown { position: static; box-shadow: none; margin-top: var(--s-1); }
}

/* --------------------------------------------------------------- cards */

.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-1);
    padding: var(--s-5);
    margin-bottom: var(--s-5);
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.muted { color: var(--text-muted); }
.linkcode {
    font-family: var(--font-mono);
    font-size: 14px;
    word-break: break-all;
}

/* ----------------------------------------------------------------- hero */

.hero {
    background: linear-gradient(150deg, var(--surface-2), var(--surface-1));
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s-7) var(--s-6);
}
.hero h1 { font-size: 34px; }
.hero h2 { font-size: 19px; font-weight: 500; color: var(--text-muted); margin-top: 0; }
.hero ul { margin: var(--s-5) 0 0; padding-left: var(--s-5); }
.hero li { margin-bottom: var(--s-2); }

/* --------------------------------------------------------- KPI cards */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--s-4);
    margin-bottom: var(--s-5);
}
.kpi {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--r-md);
    padding: var(--s-4) var(--s-5);
}
.kpi__label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: var(--s-2);
}
.kpi__value { font-size: 30px; font-weight: 700; }
.kpi--tf { border-left-color: var(--tf-accent); }
.kpi--pl { border-left-color: var(--pl-accent); }
.kpi--money .kpi__value { color: var(--success); }

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin-bottom: var(--s-4);
}
.data-table th,
.data-table td {
    padding: var(--s-2) var(--s-3);
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table thead th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table--tf thead th { color: var(--tf-accent); }
.data-table--pl thead th { color: var(--pl-accent); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table--payouts {
    display: block;
    border-collapse: initial;
    border-spacing: 0;
    margin-top: var(--s-2);
}
.data-table--payouts thead,
.data-table--payouts tbody {
    display: block;
}
.data-table--payouts thead tr,
.data-table--payouts tbody tr {
    display: grid;
    grid-template-columns: minmax(130px, 1fr) minmax(150px, 180px) minmax(170px, 1fr);
    column-gap: var(--s-5);
    align-items: center;
}
.data-table--payouts thead tr {
    margin-bottom: var(--s-2);
}
.data-table--payouts tbody {
    display: grid;
    gap: var(--s-2);
}
.data-table--payouts tbody tr {
    border-radius: var(--r-sm);
    overflow: hidden;
}
.data-table--payouts thead th,
.data-table--payouts tbody td {
    border-bottom: 0;
    padding: var(--s-4);
    text-align: left;
    white-space: nowrap;
}
.data-table--payouts tbody td {
    font-size: 15px;
    background: transparent;
}
.data-table--payouts thead .num,
.data-table--payouts tbody .num {
    text-align: left;
}
.data-table--payouts tbody tr:nth-child(odd) { background: #1d2430; }
.data-table--payouts tbody tr:nth-child(even) { background: #202836; }
.data-table--payouts tbody tr:hover { background: #252e3c; }
.payout-amount {
    color: var(--success);
    font-weight: 700;
}
.pos { color: var(--success); }
.neg { color: var(--danger); }

.campaign-title { font-weight: 650; margin: var(--s-5) 0 var(--s-2); }
.table-scroll { overflow-x: auto; }

.tf-label { color: var(--tf-accent); font-weight: 700; }
.pl-label { color: var(--pl-accent); font-weight: 700; }

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

.field { margin-bottom: var(--s-4); }
.field__label {
    display: block;
    margin-bottom: var(--s-2);
    font-weight: 550;
}
.field__hint { color: var(--text-faint); font-size: 13px; margin-top: var(--s-1); }

input[type=text],
input[type=email],
input[type=password],
textarea,
select {
    width: 100%;
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    padding: var(--s-3);
    font: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--tf-accent); }
input[readonly], input:disabled, textarea:disabled {
    opacity: .55;
    cursor: not-allowed;
}
textarea { min-height: 110px; resize: vertical; }

.btn {
    display: inline-block;
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    padding: var(--s-3) var(--s-5);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { border-color: var(--text-faint); color: var(--text); }
.btn--primary {
    background: var(--tf);
    border-color: var(--tf);
    color: #fff;
}
.btn--primary:hover { background: #1f8bff; color: #fff; }
.btn--lg { padding: var(--s-4) var(--s-6); font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

.radio-row { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-2); }
.radio-row input { width: auto; }

/* --------------------------------------------------------------- alerts */

.alert {
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-faint);
    border-radius: var(--r-sm);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
}
.alert--error   { background: var(--danger-soft);  border-left-color: var(--danger); }
.alert--success { background: var(--success-soft); border-left-color: var(--success); }
.alert--warning { background: var(--warning-soft); border-left-color: var(--warning); }
.alert--info    { background: var(--info-soft);    border-left-color: var(--info); }
.alert ul { margin: var(--s-1) 0 0; padding-left: var(--s-5); }

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

.badge {
    display: inline-block;
    font-size: 12px;
    padding: 2px var(--s-2);
    border-radius: var(--r-pill);
    background: var(--surface-3);
    color: var(--text-muted);
}

.banner-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--s-5);
    align-items: start;
}
.banner-grid figure {
    margin: 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-3);
}
.banner-grid img { max-width: 100%; height: auto; display: block; border-radius: var(--r-sm); }
.banner-grid figcaption { color: var(--text-muted); font-size: 12px; margin-top: var(--s-2); }

.auth-box { max-width: 420px; margin-inline: auto; }

.account-head {
    display: flex;
    align-items: center;
    gap: var(--s-4);
    margin-bottom: var(--s-5);
}
.account-head img { border-radius: var(--r-md); border: 1px solid var(--border); }

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