/* iPOS Partner Portal — visual styling.
 *
 * Design goals:
 *   - Match the iPOS brand: navy header, navy primary buttons, white logo.
 *   - Read well on desktop (where partners most commonly check email) AND
 *     on a phone (touch targets >= 44px, table degrades to stacked cards).
 *   - Status pills colour-coded the same way as the Android + web apps, so
 *     someone glancing across the three surfaces sees identical visual
 *     vocabulary.
 */

/* ───── Variables ───────────────────────────────────────────────────────── */
:root {
    --navy: #002C4B;
    --navy-dark: #001a2d;
    --grey-text: #333;
    --grey-muted: #666;
    --grey-line: #e5e5e5;
    --grey-bg: #f6f7f9;
    --grey-card: #ffffff;

    /* Status pill palette — matches the Android + web apps so the same record
     * looks identical across all three surfaces. 3-state lifecycle: blue for
     * just-arrived, purple while being worked, green when closed. */
    --pill-submitted-bg: #D6E4FF;
    --pill-submitted-fg: #1B4D8E;
    --pill-in_progress-bg: #EDE0FF;
    --pill-in_progress-fg: #5D3F8C;
    --pill-closed-bg: #D6F5E3;
    --pill-closed-fg: #1F6A3E;

    --error-bg: #fde8e8;
    --error-fg: #9a2222;
}

/* ───── Reset-ish ───────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--grey-text);
    background: var(--grey-bg);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ───── Header band ─────────────────────────────────────────────────────── */
.brand {
    background: var(--navy);
    color: #fff;
    padding: 14px 0;
}
.brand-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.brand .logo {
    height: 28px;
    width: auto;
    display: block;
}
.brand .brand-text {
    font-size: 14px;
    letter-spacing: 0.5px;
    opacity: 0.85;
}
.brand .logout {
    margin-left: auto;
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
}
.brand .logout:hover { background: rgba(255, 255, 255, 0.1); }

/* ───── Layout ──────────────────────────────────────────────────────────── */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

/* ───── Cards / login ───────────────────────────────────────────────────── */
.card {
    background: var(--grey-card);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.login-card {
    max-width: 420px;
    margin: 40px auto 0;
}
.login-card h1 {
    margin: 0 0 6px 0;
    font-size: 22px;
}
.muted {
    color: var(--grey-muted);
    font-size: 14px;
}

/* ───── Forms ───────────────────────────────────────────────────────────── */
.field {
    display: block;
    margin-top: 18px;
}
.field > span {
    display: block;
    font-size: 13px;
    color: var(--grey-muted);
    margin-bottom: 6px;
}
.field select,
.field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--grey-line);
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    background: #fff;
}
.field select:focus,
.field input:focus {
    outline: none;
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(0, 44, 75, 0.15);
}

button.primary {
    width: 100%;
    margin-top: 22px;
    background: var(--navy);
    color: #fff;
    border: none;
    padding: 11px 18px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
button.primary:hover { background: var(--navy-dark); }
button.primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

button.ghost {
    background: transparent;
    border: 1px solid var(--grey-line);
    padding: 7px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--grey-text);
}
button.ghost:hover { background: var(--grey-bg); }

/* ───── Error states ────────────────────────────────────────────────────── */
.error {
    margin-top: 16px;
    padding: 10px 12px;
    background: var(--error-bg);
    color: var(--error-fg);
    border-radius: 6px;
    font-size: 14px;
}

/* ───── Stats row ───────────────────────────────────────────────────────── */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--grey-card);
    border-radius: 8px;
    padding: 16px 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.stat-num {
    font-size: 28px;
    font-weight: 600;
    color: var(--navy);
}
.stat-label {
    font-size: 12px;
    color: var(--grey-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* ───── Dashboard header ────────────────────────────────────────────────── */
.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 4px 0 14px;
}
.dashboard-header h2 {
    margin: 0;
    font-size: 18px;
}

/* ───── Table ───────────────────────────────────────────────────────────── */
#referrals-wrap {
    background: var(--grey-card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
thead th {
    text-align: left;
    background: #fafbfc;
    color: var(--grey-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--grey-line);
}
tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--grey-line);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
.status-col { width: 200px; }
.commission-col { width: 160px; text-align: right; white-space: nowrap; }

/* Commission cell: amount + tiny "edit" affordance. Muted dash for non-closed
 * rows so the visual weight matches their lack of meaning at that lifecycle
 * stage. */
.commission-cell { display: inline-flex; align-items: baseline; gap: 8px; justify-content: flex-end; }
.commission-cell.muted { color: #94a3b8; }
.commission-amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.commission-edit {
    background: none;
    border: none;
    color: #2563eb;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    text-decoration: underline;
}
.commission-edit:hover { color: #1d4ed8; }

/* Inline status dropdown styled as a coloured pill that matches the current
 * status. Lets partners scan their list visually — a row of amber dropdowns
 * means "I have a lot to contact", a row of purple means "I'm in active
 * conversation", etc. The dropdown flips colour the instant the row
 * re-renders after a successful PATCH, giving immediate confirmation. */
.status-select {
    width: 100%;
    padding: 7px 28px 7px 12px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    /* Hide the native dropdown arrow — we draw our own chevron via SVG. */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M2 4 L6 8 L10 4' stroke='currentColor' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 10px;
}
.status-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 44, 75, 0.18);
}

/* Status-colour variants. Set via data-status on the <select> from JS. */
.status-select[data-status="submitted"] {
    background-color: var(--pill-submitted-bg);
    color: var(--pill-submitted-fg);
}
.status-select[data-status="in_progress"] {
    background-color: var(--pill-in_progress-bg);
    color: var(--pill-in_progress-fg);
}
.status-select[data-status="closed"] {
    background-color: var(--pill-closed-bg);
    color: var(--pill-closed-fg);
}

/* ───── Status pills (used in a future read-only state, or alongside select) */
.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.pill-submitted   { background: var(--pill-submitted-bg);   color: var(--pill-submitted-fg); }
.pill-in_progress { background: var(--pill-in_progress-bg); color: var(--pill-in_progress-fg); }
.pill-closed      { background: var(--pill-closed-bg);      color: var(--pill-closed-fg); }

/* ───── Subtle "row is saving" indicator ────────────────────────────────── */
tr.saving { background: rgba(0, 44, 75, 0.04); }
tr.error-row .status-select { border-color: var(--error-fg); }

#empty-state, #load-error { padding: 28px 16px; }

/* ───── Phone-sized screens — collapse table into card-per-row ──────────── */
@media (max-width: 720px) {
    .stats { grid-template-columns: repeat(2, 1fr); }

    /* Hide the thead; render each row as a stacked block with labels. */
    thead { display: none; }
    table, tbody, tr, td { display: block; width: 100%; }
    tbody tr {
        padding: 14px 0;
        border-bottom: 1px solid var(--grey-line);
    }
    tbody tr:last-child { border-bottom: none; }
    tbody td {
        padding: 6px 16px;
        border: none;
    }
    tbody td::before {
        content: attr(data-label);
        display: block;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--grey-muted);
        margin-bottom: 2px;
    }
    .status-col { width: auto; }
}
