:root {
    --wa-green: #00a884;
    --wa-green-dark: #008069;
    --wa-teal: #075e54;
    --wa-teal-2: #128c7e;
    --bg: #f0f2f5;
    --panel: #ffffff;
    --panel-2: #f7f8fa;
    --border: #e9edef;
    --border-2: #d1d7db;
    --ink: #111b21;
    --muted: #667781;
    --muted-2: #8696a0;
    --badge: #25d366;
    --badge-ink: #ffffff;
    --danger: #ea0038;
    --hover: #f5f6f6;
    --accent-ink: #008069;
    --th-bg: #f5f6f6;
    --th-ink: #41525d;
    --striped: #fafafa;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: 'Segoe UI', 'Helvetica Neue', Tahoma, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    font-size: 14px;
}

[hidden] { display: none !important; }

button { font-family: inherit; }

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.screen {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* ------------------------------------------------------------------ */
/* Buttons, chips, spinner                                             */
/* ------------------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    padding: 11px 22px;
    color: #fff;
    background: var(--wa-green-dark);
    cursor: pointer;
    transition: background .15s ease;
    white-space: nowrap;
}

.btn svg { width: 18px; height: 18px; flex: none; }

.btn:hover:not(:disabled) { background: var(--wa-teal-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
    background: var(--wa-green);
    box-shadow: 0 1px 2px rgba(11, 20, 26, .12);
}

.btn-primary:hover:not(:disabled) { background: var(--wa-green-dark); }

.btn-ghost {
    background: #fff;
    color: var(--accent-ink);
    border: 1px solid var(--border-2);
    font-weight: 600;
}

.btn-ghost:hover:not(:disabled) { background: var(--hover); }

.btn-small { padding: 7px 14px; font-size: 13px; }

.icon-btn {
    border: none;
    background: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--ink);
    flex: none;
}

.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { background: rgba(0, 0, 0, .06); }

.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid #e1e6ea;
    border-top-color: var(--wa-green);
    border-radius: 50%;
    animation: spin .9s linear infinite;
    margin: 18px auto;
}

.spinner-sm {
    width: 18px;
    height: 18px;
    border: 3px solid #dfe7ea;
    border-top-color: var(--wa-green-dark);
    margin: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.dot-spin {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    animation: spin .8s linear infinite;
}

.muted { color: var(--muted); font-size: 12px; margin: 2px 0 0; }

/* ------------------------------------------------------------------ */
/* Login                                                               */
/* ------------------------------------------------------------------ */

.login-screen {
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 12% 8%, rgba(0, 168, 132, .12), transparent 42%),
        radial-gradient(circle at 88% 92%, rgba(18, 140, 126, .10), transparent 45%),
        var(--bg);
    padding: 24px;
    gap: 14px;
}

.login-card {
    width: min(920px, 100%);
    min-height: 470px;
    background: var(--panel);
    border-radius: 16px;
    box-shadow: 0 12px 34px rgba(11, 20, 26, .14);
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    overflow: hidden;
}

.login-side {
    padding: 46px 42px 40px;
    background:
        linear-gradient(160deg, rgba(0, 168, 132, .05), transparent 55%),
        var(--panel-2);
    border-right: 1px solid var(--border);
}

.brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }

.brand-badge {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--wa-green), var(--wa-teal-2));
    color: #fff;
    font-weight: 800;
    font-size: 18px;
    letter-spacing: .5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 14px rgba(0, 168, 132, .35);
}

.brand-row h1 { margin: 0; font-size: 24px; color: var(--ink); }

.login-lead {
    margin: 0 0 8px;
    font-size: 26px;
    font-weight: 600;
    line-height: 1.2;
}

.login-sub { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.6; }

.login-divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

.login-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }

.login-steps li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
}

.login-steps li span {
    flex: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--wa-green);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.login-stage {
    padding: 46px 34px 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.login-stage h2 { margin: 0 0 6px; font-size: 18px; }

.login-stage img {
    width: 264px;
    height: 264px;
    border: 1px solid var(--border-2);
    border-radius: 8px;
    background: #fff;
    padding: 4px;
}

.stage-text { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.stage-hint { color: var(--muted-2); font-size: 12.5px; line-height: 1.6; margin: 10px 0 0; max-width: 300px; }
.stage-notice {
    color: #7a4d00;
    background: #fff2d5;
    border: 1px solid #ffe0a3;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    padding: 8px 12px;
    margin: 12px 0 0;
    max-width: 300px;
}
.stage-error {
    color: var(--danger);
    background: #fde8ee;
    border: 1px solid #f6bdc9;
    border-radius: 8px;
    font-size: 13px;
    padding: 8px 12px;
    margin: 12px 0 0;
    word-break: break-word;
}

/* "Continue to Groups" escape hatch when a saved session cannot connect. */
.stage-skip { margin: 14px 0 0; }

.login-foot { color: var(--muted-2); font-size: 12px; text-align: center; margin: 0; }

/* ------------------------------------------------------------------ */
/* App top bar                                                         */
/* ------------------------------------------------------------------ */

.app-top {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--border-2);
    padding: 8px 18px;
    min-height: 62px;
}

.top-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.top-titles { min-width: 0; }
.top-titles h1 { margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-titles .muted { margin: 1px 0 0; }

.top-right { display: flex; align-items: center; gap: 10px; flex: none; }

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--wa-green), var(--wa-teal-2));
    color: #fff;
    font-weight: 700;
    font-size: 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.conn-menu { position: relative; }

.conn-chip {
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 12px;
    background: var(--panel-2);
    color: var(--muted);
    border: 1px solid var(--border);
    white-space: nowrap;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.conn-chip:hover { border-color: var(--border-2); }

.conn-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 40;
    min-width: 230px;
    padding: 6px;
    background: var(--panel);
    border: 1px solid var(--border-2);
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(11, 20, 26, 0.14);
}

.conn-dropdown-user {
    margin: 0;
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.conn-dropdown-phone {
    margin: -4px 0 0;
    padding: 0 10px 8px;
    font-size: 12px;
    color: var(--muted);
    direction: ltr;
    text-align: left;
}

/* Checkbox and Logout share one row below the username. */
.conn-dropdown-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 10px;
    border-top: 1px solid var(--border);
}

.conn-dropdown-delete {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}

.conn-dropdown-delete input { accent-color: var(--danger); margin: 0; }

.conn-dropdown-logout {
    padding: 6px 10px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--danger);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.conn-dropdown-logout:hover:not(:disabled) { background: var(--panel-2); }
.conn-dropdown-logout:disabled { color: var(--muted-2); cursor: default; }

.conn-chip.ready { color: #0b8f4b; background: #e6f8ee; border-color: #b9ecd0; }

/* Chevron marking the connected username as a dropdown toggle. */
.conn-chip.ready::after {
    content: "";
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 6px;
    vertical-align: 1px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform 0.15s ease;
}

.conn-chip.ready[aria-expanded="true"]::after { transform: rotate(180deg); }

/* Saved session whose lazy connect is in flight: the gray username pulses. */
.conn-chip.connecting { animation: conn-chip-pulse 1.2s ease-in-out infinite; }

@keyframes conn-chip-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

.sync-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--wa-green-dark);
    background: #e6f8ee;
    border: 1px solid #b9ecd0;
    border-radius: 12px;
    padding: 5px 12px;
}

/* ------------------------------------------------------------------ */
/* Groups                                                              */
/* ------------------------------------------------------------------ */

.groups-screen { background: var(--panel); }

.groups-toolbar {
    flex: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

.groups-toolbar input[type="search"] {
    flex: 1;
    min-width: 0;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    font-size: 14px;
    outline: none;
}

.groups-toolbar input[type="search"]:focus {
    background: #fff;
    border-color: var(--wa-green);
    box-shadow: 0 0 0 2px rgba(0, 168, 132, .18);
}

.check-all {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    flex: none;
}

.groups-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    border-bottom: 1px solid var(--border-2);
}

.group-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 18px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .1s ease;
}

.group-row:hover { background: var(--hover); }

.group-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--wa-green);
    flex: none;
    cursor: pointer;
}

.g-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #e9edef;
    color: var(--muted);
    font-weight: 700;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    overflow: hidden;
}

.g-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.g-name {
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    direction: rtl;
    text-align: right;
}

.g-sub { font-size: 12.5px; color: var(--muted-2); direction: rtl; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.g-badge {
    flex: none;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    background: var(--badge);
    color: var(--badge-ink);
    font-size: 12px;
    font-weight: 700;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.groups-list .empty {
    padding: 60px 24px;
    text-align: center;
    color: var(--muted);
}

.groups-action {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 18px;
    background: var(--panel);
    border-top: 1px solid var(--border-2);
    flex-wrap: wrap;
}

.sel-summary { min-width: 0; }
.sel-summary p { margin: 0; }
.sel-summary .muted { margin-top: 3px; }

.sel-actions { display: flex; align-items: center; gap: 10px; flex: none; }

/* ------------------------------------------------------------------ */
/* Message information                                                 */
/* ------------------------------------------------------------------ */

.info-screen { background: var(--bg); }

.run-panel {
    flex: none;
    margin: 0 18px 14px;
    background: var(--panel);
    border: 1px solid var(--border-2);
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.run-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
}

.run-status.ok { color: #0b8f4b; }
.run-status.err { color: var(--danger); }

.run-status .status-icon {
    width: 18px;
    height: 18px;
    flex: none;
}

.job-log summary {
    cursor: pointer;
    color: var(--accent-ink);
    font-size: 13px;
    font-weight: 600;
    user-select: none;
}

.job-log pre {
    background: #111b21;
    color: #d9e2e7;
    border-radius: 8px;
    padding: 10px 12px;
    max-height: 220px;
    overflow-y: auto;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 8px 0 0;
}

.tabs-bar {
    flex: none;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding-right: 18px;
}

.tabs {
    flex: 1;
    min-width: 0;
    display: flex;
    gap: 2px;
    /* 1px bottom padding absorbs the tabs' -1px bottom margin so the nav has
       no vertical scroll range at all; the -1px bottom margin keeps the tabs
       lapping over the table border exactly like before. */
    padding: 14px 0 1px 18px;
    margin-bottom: -1px;
    /* Horizontal scrolling only: the tabs must never scroll vertically, so
       the computed overflow-y stays hidden (a bare overflow-x: auto would
       compute overflow-y to auto and let a stray vertical scrollbar appear
       when the row overflows). */
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

/* The horizontal scrollbar is hidden so it cannot take height from the tabs
   and clip them; the nav is still scrollable by wheel/trackpad. */
.tabs::-webkit-scrollbar {
    display: none;
}

/* Status filter, inline on the tabs row and right-aligned. */
.results-filter {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 7px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

/* Hides the browser's native select indicator and draws a small downward
   arrow inside the Status filter so it is clearly a dropdown menu. */
.results-filter .s-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z' fill='%23667781'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 14px 14px;
    padding-right: 24px;
}

.tab {
    border: 1px solid var(--border-2);
    background: var(--panel);
    color: var(--muted);
    font-size: 13.5px;
    font-weight: 600;
    padding: 9px 18px;
    border-radius: 10px 10px 0 0;
    cursor: pointer;
    white-space: nowrap;
    margin-bottom: -1px;
    border-bottom: none;
    position: relative;
}

.tab:hover { color: var(--ink); }
.tab.active {
    color: var(--wa-green-dark);
    background: var(--bg);
    border-color: var(--border-2);
    box-shadow: inset 0 3px 0 var(--wa-green);
}

.tab .count { opacity: .7; font-weight: 500; margin-left: 4px; }

/* Row selection toolbar (shown while messages are selected). */
.row-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 18px 12px;
}

.row-actions-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-ink);
}

.row-actions-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Row action buttons: muted, tinted status colors so the toolbar is less
   bright while every action stays distinguishable (grey Unreview, amber
   Review, green Accept, red Reject). */
.btn-unreview {
    background: #cfdde6;
    color: #46585f;
    border: 1px solid #b9cbd6;
}

.btn-unreview:hover:not(:disabled) { background: #c2d4de; }

.btn-review {
    background: #f2e2bd;
    color: #7a5a1f;
    border: 1px solid #e2cd9a;
}

.btn-review:hover:not(:disabled) { background: #ebd7a4; }

.btn-accept {
    background: #cfe8da;
    color: #2b5f3f;
    border: 1px solid #b4d6c2;
}

.btn-accept:hover:not(:disabled) { background: #c0e0cd; }

.btn-reject {
    background: #f2d3d3;
    color: #8f3a3a;
    border: 1px solid #e0bcbc;
}

.btn-reject:hover:not(:disabled) { background: #e9c4c4; }

.results {
    flex: 1;
    min-height: 0;
    padding: 0 18px 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.info-actions {
    flex: none;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px;
    background: var(--panel);
    border-top: 1px solid var(--border-2);
}

/* Short save feedback shown while editing the commercial fields. */
.info-toast {
    position: fixed;
    right: 24px;
    bottom: 84px;
    z-index: 50;
    max-width: min(420px, calc(100vw - 48px));
    padding: 9px 14px;
    border-radius: 8px;
    background: #0b8f4b;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}

.info-toast.err { background: var(--danger); }

/* Send-message modal (opened from the Phone column). */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(11, 20, 26, .45);
}

.modal-card {
    width: min(460px, 100%);
    background: var(--panel);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
}

.modal-card h3 {
    margin: 0 0 6px;
    font-size: 16px;
}

.modal-recipient {
    margin: 0 0 12px;
    font-size: 13px;
    word-break: break-word;
}

.modal-card textarea {
    box-sizing: border-box;
    width: 100%;
    min-height: 96px;
    resize: vertical;
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--border-2);
    border-radius: 8px;
    color: inherit;
}

.modal-card textarea:focus {
    outline: none;
    border-color: var(--wa-green);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

.table-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--border-2);
    /* Visible separator between the tab strip and the table header row. The
       active tab only laps over the first pixel, so the line stays readable
       under it too. */
    border-top: 2px solid var(--muted-2);
    border-radius: 0 0 10px 10px;
}

.table-scroll table {
    width: 100%;
    min-width: 1500px;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

.table-scroll thead th {
    background: var(--th-bg);
    color: var(--th-ink);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    text-align: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-2);
    border-right: 1px solid var(--border-2);
    white-space: nowrap;
}

.table-scroll td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-2);
    border-right: 1px solid var(--border-2);
    vertical-align: top;
    /* Wrap at word boundaries (spaces); break inside a word only when the
       word cannot fit the cell at all. `anywhere`/`break-word` splitting
       chops Persian words and disconnects their letter forms. */
    word-break: normal;
    overflow-wrap: break-word;
    line-height: 1.5;
    overflow: hidden;
}

/* The last column has no right border. A dedicated class is used instead of
   :last-child because in split (multi-product) rows the last cell of the
   non-first rows is not the last column (Notes spans the rows with rowspan),
   and :last-child would strip the Supplier Price border there. */
.table-scroll th.last-col,
.table-scroll td.last-col { border-right: none; }

.table-scroll tbody tr:nth-child(even) td { background: var(--striped); }

.table-scroll tbody tr:hover td { background: #f2fcf9; }

/* Multi-product purchase rows: every product is its own <tr>, so keep the
   whole message on a single background (the row borders are the visible
   separators between products). */
.table-scroll tbody tr.split-row td { background: var(--panel); }
.table-scroll tbody tr.split-row:hover td { background: #f2fcf9; }

/* Selected messages (all rows of a split message share the tint). */
.table-scroll tbody tr.selected td { background: #e6f7f1; }
.table-scroll tbody tr.selected:hover td { background: #dcf3ea; }

/* Row selection checkbox + written review status. */
td.select {
    text-align: center;
    vertical-align: middle;
    padding: 10px 6px;
}

.row-select {
    display: block;
    width: 12px;
    height: 12px;
    margin: 4px auto 0;
    cursor: pointer;
    accent-color: var(--wa-green);
}

.status-text {
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1.3;
    word-break: normal;
    overflow-wrap: normal;
    color: var(--muted);
}

.status-text.status-unreviewed { color: var(--muted); }
.status-text.status-underReview { color: #a06b00; }
.status-text.status-accepted { color: #0b7a41; }
.status-text.status-rejected { color: var(--danger); }

/* Content direction is per cell: `dir="auto"` picks LTR for English (left)
   and RTL for Persian (right). Numeric-only cells stay LTR/left. */
td.num { direction: ltr; text-align: left; }
td.msg { white-space: pre-wrap; }

/* The phone number is a single unbreakable token: never wrap it or break it
   mid-number (the column is wide enough for the full value). */
td.phone {
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
}

/* Author names that are actually phone numbers stay on one line too (the
   number has no strong character, so `dir=auto` falls back to LTR/left). */
td.nowrap-cell {
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
}

/* Sends a WhatsApp message to the message author; sits under the phone
   number in the Phone column. */
.send-msg-btn {
    display: block;
    margin-top: 6px;
    padding: 4px 10px;
    font-size: 11.5px;
}

/* Editable commercial cells: plain text until hovered/focused. Rendered as
   auto-growing textareas so multi-word values (e.g. Notes) wrap and stay
   fully readable. */
.cell-edit {
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    padding: 4px 6px;
    font: inherit;
    line-height: 1.5;
    color: inherit;
    /* Align to the text's own direction (`dir="auto"`): English left, Persian
       right. Numeric inputs override this with LTR/left. */
    text-align: start;
    resize: none;
    overflow: hidden;
    white-space: pre-wrap;
    /* Keep words intact: wrap at spaces, only break inside a word when it
       cannot fit the cell at all (see the td rule above). */
    word-break: normal;
    overflow-wrap: break-word;
}

.cell-edit:hover { border-color: var(--border-2); }

/* The per-product supplier sub-cells are single-line inputs; they inherit the
   .cell-edit look. */
input.cell-edit {
    height: auto;
    line-height: 1.5;
}

/* The Product Profit input holds a formatted number; keep it LTR/left like
   the other numeric cells (.cell-edit otherwise aligns to the text's own
   direction). */
input.cell-edit.numeric {
    direction: ltr;
    text-align: left;
}

.cell-edit:focus {
    outline: none;
    border-color: var(--wa-green);
    background: var(--panel);
}

.cell-edit::placeholder { color: var(--muted-2); opacity: 1; }
.cell-edit.saving { opacity: .55; }
.cell-edit.save-error { border-color: var(--danger); }

.col-id { width: 7%; }
.col-select { width: 6%; }
.col-group { width: 8%; }
.col-msg { width: 17%; }
.col-author { width: 10%; }
.col-phone { width: 11%; }
.col-quantity { width: 9%; }
.col-date { width: 9%; }
.col-product { width: 14%; }
.col-price { width: 6%; }
.col-services { width: 12.5%; }
.col-suppliers { width: 9%; }
.col-supplier-price { width: 12%; }
.col-notes { width: 16%; }

/* Five table layouts, all sharing the leading select column (which carries
   the checkbox and the written review status). The base widths are the
   no-optional-column layout (Other) and sum to 100%; each variant adds its
   columns and rebalances Message/Notes/Product (and Suppliers/Profit on
   Purchase) so the layout still sums to 100%:
   - Sale / Sale of Other Products add Price;
   - Service Requests add Services Requested;
   - Purchase of Other Products adds Suppliers + Supplier Price;
   - Purchase adds Product Profit + Suppliers + Supplier Price.
   Every width is tuned so the uppercase headers fit on one line and the phone
   numbers fit the Phone column (even a raw 17-char jid) at the table's
   1500px minimum width; the Author column fits phone-formatted author names
   on one line and the Product column keeps its longest word
   ("مونوکریستال", ~70px) on one line. The Message column is kept as wide as
   the remaining columns allow so message bodies wrap in fewer lines. */
.col-profit { width: 10%; }

table.with-price .col-msg { width: 16%; }
table.with-price .col-product { width: 13%; }
table.with-price .col-notes { width: 12%; }

table.with-services .col-msg { width: 14%; }
table.with-services .col-product { width: 12%; }
table.with-services .col-notes { width: 8.5%; }

table.with-suppliers .col-msg { width: 12%; }
table.with-suppliers .col-product { width: 9%; }
table.with-suppliers .col-suppliers { width: 8%; }
table.with-suppliers .col-notes { width: 6%; }

table.with-profit-suppliers .col-msg { width: 9%; }
table.with-profit-suppliers .col-quantity { width: 7%; }
table.with-profit-suppliers .col-date { width: 6%; }
table.with-profit-suppliers .col-product { width: 8%; }
table.with-profit-suppliers .col-suppliers { width: 8%; }
table.with-profit-suppliers .col-supplier-price { width: 11%; }
table.with-profit-suppliers .col-notes { width: 6%; }

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--border-2);
    border-radius: 10px;
    color: var(--muted);
    text-align: center;
    padding: 40px 24px;
}

.empty-state .big { font-size: 34px; opacity: .5; }

/* ------------------------------------------------------------------ */
/* Small screens                                                       */
/* ------------------------------------------------------------------ */

@media (max-width: 1020px) {
    .groups-layout { flex-direction: column; }
    .side-panel {
        width: auto;
        border-left: none;
        border-top: 1px solid var(--border-2);
        flex-direction: row;
        flex-wrap: wrap;
    }
    .side-panel .panel-card { flex: 1 1 260px; }
}

@media (max-width: 820px) {
    .login-card { grid-template-columns: 1fr; min-height: 0; }
    .login-side { padding: 30px 26px 24px; border-right: none; border-bottom: 1px solid var(--border); }
    .login-stage { padding: 30px 20px; }
    .groups-action { justify-content: center; }
    .groups-action .sel-summary { text-align: center; }
    .side-panel { flex-direction: column; }
}

/* ------------------------------------------------------------------ */
/* Account login / create account                                      */
/* ------------------------------------------------------------------ */

.auth-screen {
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 12% 8%, rgba(0, 168, 132, .12), transparent 42%),
        radial-gradient(circle at 88% 92%, rgba(18, 140, 126, .10), transparent 45%),
        var(--bg);
    padding: 24px;
    overflow-y: auto;
}

.auth-wrap {
    width: min(440px, 100%);
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
}

.auth-brand .brand-badge {
    width: 58px;
    height: 58px;
    font-size: 22px;
    margin-bottom: 8px;
}

.auth-brand h1 { margin: 0; font-size: 26px; color: var(--ink); }

.auth-brand p {
    margin: 8px 0 0;
    max-width: 340px;
    color: var(--muted);
    font-size: 13.5px;
    line-height: 1.6;
}

.auth-card {
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--border-2);
    border-radius: 14px;
    box-shadow: 0 12px 34px rgba(11, 20, 26, .12);
    overflow: hidden;
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid var(--border);
}

.auth-tabs button {
    background: none;
    border: none;
    padding: 14px 10px;
    font-size: 14.5px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color .15s ease, background .15s ease;
}

.auth-tabs button:hover { color: var(--ink); }

.auth-tabs button.active {
    color: var(--wa-green-dark);
    border-bottom-color: var(--wa-green);
    background: var(--panel-2);
}

.auth-body { padding: 24px 26px; }

.auth-form { display: flex; flex-direction: column; gap: 15px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field > span {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
}

.field .optional { color: var(--muted-2); font-weight: 400; }

.text-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-2);
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    outline: none;
}

.text-input:focus {
    border-color: var(--wa-green);
    box-shadow: 0 0 0 2px rgba(0, 168, 132, .18);
}

.form-error {
    margin: 0;
    color: var(--danger);
    background: #fde8ee;
    border: 1px solid #f6bdc9;
    border-radius: 8px;
    font-size: 13px;
    padding: 8px 12px;
    word-break: break-word;
}

.auth-alt {
    margin: 0;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

.auth-alt button {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent-ink);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

.auth-alt button:hover { text-decoration: underline; }

.link-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent-ink);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
}

.link-btn:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ */
/* Groups layout with side panel                                       */
/* ------------------------------------------------------------------ */

.groups-layout {
    flex: 1;
    min-height: 0;
    display: flex;
}

.groups-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.side-panel {
    flex: none;
    width: 320px;
    min-height: 0;
    overflow-y: auto;
    background: var(--panel-2);
    border-left: 1px solid var(--border-2);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    flex: none;
}

.panel-head {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    font-weight: 700;
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-body { padding: 14px; display: flex; flex-direction: column; gap: 12px; }

.p-identity { display: flex; align-items: center; gap: 12px; }

.avatar-lg {
    width: 54px;
    height: 54px;
    font-size: 21px;
}

.p-titles { min-width: 0; }

.p-name {
    margin: 0;
    font-size: 15.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    direction: rtl;
    text-align: right;
}

.p-handle {
    margin: 1px 0 0;
    font-size: 12.5px;
    color: var(--muted-2);
    direction: ltr;
    text-align: left;
}

.p-details {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 12.5px;
}

.p-details div { display: flex; gap: 8px; }

.p-details dt {
    flex: none;
    width: 62px;
    color: var(--muted);
}

.p-details dd {
    margin: 0;
    min-width: 0;
    word-break: break-word;
    direction: ltr;
    text-align: left;
}

.p-form { display: flex; flex-direction: column; gap: 11px; }
.p-form-actions { display: flex; gap: 8px; }

.s-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
}

.s-row .s-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
}

.s-row .s-select { flex: none; }

.s-select {
    border: 1px solid var(--border-2);
    border-radius: 6px;
    background: #fff;
    font-family: inherit;
    font-size: 12.5px;
    color: var(--ink);
    padding: 4px 8px;
    max-width: 150px;
    cursor: pointer;
}

.s-select:focus {
    outline: none;
    border-color: var(--wa-green);
    box-shadow: 0 0 0 2px rgba(0, 168, 132, .18);
}

.s-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12.5px;
    color: var(--ink);
    user-select: none;
}

.s-check input {
    accent-color: var(--wa-green);
    cursor: pointer;
}

.btn-block { width: 100%; }

.btn-danger { color: var(--danger); border-color: #f6bdc9; }
.btn-danger:hover:not(:disabled) { background: #fde8ee; }
