:root {
    --ink: #1c2733;
    --muted: #64748b;
    --line: #dbe2ea;
    --bg: #f3f5f8;
    --card: #ffffff;
    --accent: #0f6ab4;
    --ok-bg: #e3f4e8;  --ok-ink: #1d7a3e;
    --warn-bg: #fdf0dc; --warn-ink: #9a6200;
    --off-bg: #eceff3;  --off-ink: #5b6673;
    --danger: #b3261e;
}

:root {
    --sidebar: #10222f;
    --sidebar-ink: #cdd8e3;
    --sidebar-active: #0f6ab4;
}

* { box-sizing: border-box; }
body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 15px/1.5 "Segoe UI", system-ui, sans-serif;
}

/* ---------- app shell: sidebar + content ---------- */
body.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px; flex: 0 0 240px; background: var(--sidebar); color: var(--sidebar-ink);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px; font-size: 17px; font-weight: 600; color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand.center { justify-content: center; border: 0; }
.brand-mark {
    display: inline-grid; place-items: center; width: 30px; height: 30px;
    background: var(--sidebar-active); border-radius: 7px; font-size: 13px; font-weight: 700; color: #fff;
}
.menu { display: flex; flex-direction: column; padding: 12px 0; flex: 1; }
.menu-item {
    padding: 10px 20px; color: var(--sidebar-ink); text-decoration: none; font-size: 14px;
    border-left: 3px solid transparent;
}
.menu-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.menu-item.active {
    background: rgba(15,106,180,.18); color: #fff; border-left-color: var(--sidebar-active); font-weight: 600;
}
.sidebar-foot {
    padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who-name { color: #fff; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-sub { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.who-pos { color: #cdd8e3; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-role { color: #7fb2e0; font-size: 12px; white-space: nowrap; }
.who-sub .who-pos + .who-role::before { content: "· "; color: #56697b; }
.link-btn {
    background: none; border: 0; color: #8bb6dc; padding: 0; font-size: 13px;
    cursor: pointer; text-decoration: underline;
}

.content { flex: 1; padding: 24px 28px; min-width: 0; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head .sub { margin: 2px 0 20px; color: var(--muted); }

/* ---------- login ---------- */
body.login-page {
    display: grid; place-items: center; min-height: 100vh; padding: 24px;
}
.login-card {
    background: var(--card); border: 1px solid var(--line); border-radius: 10px;
    padding: 28px 30px; width: 340px; box-shadow: 0 8px 30px rgba(16,34,47,.08);
}
.login-card .brand { border: 0; padding: 0 0 10px; color: var(--ink); }
.login-card h1 { margin: 0 0 18px; font-size: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.login-card input {
    padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; color: var(--ink);
}
button.full { width: 100%; padding: 9px; }
.btn.full { width: 100%; padding: 9px; text-align: center; }
.btn.center-btn { display: block; margin-top: 8px; }
.login-foot { margin: 14px 0 0; text-align: center; font-size: 13px; }
.login-foot a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }

.card {
    background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    padding: 18px 20px; margin-bottom: 20px; max-width: 1100px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }

.pill {
    display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px;
}
.pill.ok   { background: var(--ok-bg);   color: var(--ok-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.off  { background: var(--off-bg);  color: var(--off-ink); }

.btn, button {
    display: inline-block; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--accent);
    background: var(--accent); color: #fff; text-decoration: none; font-size: 14px; cursor: pointer;
}
button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }

.actions { white-space: nowrap; }
.actions form.inline { display: inline; margin-left: 6px; }
.actions details { display: inline-block; }
.actions details summary { cursor: pointer; color: var(--accent); }
/* compact stacked mini-form used inside table row actions (edit, set token…) */
.inline-form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; width: 240px; }
.inline-form input, .inline-form select {
    padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
    width: 100%; max-width: 100%; font-size: 14px; color: var(--ink);
}
.inline-form button { align-self: flex-start; }

.add-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.add-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.add-form input, .add-form select {
    padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; color: var(--ink);
}

.notice.ok {
    background: var(--ok-bg); color: var(--ok-ink); border: 1px solid #bfe4cb;
    border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; max-width: 1100px;
}
.notice.err {
    background: #fbe6e4; color: var(--danger); border: 1px solid #f2c4bf;
    border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; max-width: 1100px;
}
.empty, .hint { color: var(--muted); }
.empty { margin: 0; }
.hint { font-size: 13px; margin-top: 10px; }

/* ---------- forms / actions ---------- */
.add-form label.check {
    flex-direction: row; align-items: center; gap: 7px; color: var(--ink); font-size: 14px;
}
.add-form label.check input { width: auto; }
.actions { white-space: normal; }
.actions form.inline, .actions details { margin: 0 6px 4px 0; }
.actions button { margin-bottom: 4px; }

/* ---------- permission grid ---------- */
.perm-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; max-width: 460px; }
.perm-row {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: 8px;
}
.perm-row input { width: auto; }
.perm-name { font-weight: 600; }
.perm-code { margin-left: auto; color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }

/* ---------- one-time invite / reset link banner ---------- */
.link-box {
    background: #eef6fd; border: 1px solid #bcdcf5; border-radius: 8px;
    padding: 12px 14px; margin-bottom: 18px; max-width: 1100px;
}
.link-box-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; margin-bottom: 8px; }
.link-box-head .muted { font-size: 13px; }
.link-row { display: flex; gap: 8px; }
.link-row input {
    flex: 1; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
    font-family: ui-monospace, monospace; font-size: 13px; background: #fff; color: var(--ink);
}

/* ---------- channel-accounts table polish ---------- */
.table-wrap { overflow-x: auto; }               /* wide table scrolls instead of breaking the page */
/* marketplace logo to the left of the channel name */
.ch-cell { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.ch-logo {
    width: 24px; height: 24px; flex: 0 0 auto; display: block;
    border-radius: 6px; object-fit: cover;   /* full-bleed square logo, rounded uniformly */
}
th, td { vertical-align: middle; }
.col-actions { width: 1%; }                      /* actions column hugs its content */
.nowrap { white-space: nowrap; }
tr.editing td { background: #f6fafd; }

/* one consistent row of equal-height action buttons — no more stray-wrapping Delete */
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end; }
.btn-row form { margin: 0; display: inline-flex; }
.btn-row .btn, .btn-row button, .btn-row summary { margin: 0; line-height: 1.4; }

/* secondary (ghost) buttons: Edit / Cancel / Token — quieter than the primary blue */
.btn.ghost, button.ghost, summary.ghost {
    background: #fff; color: var(--accent); border: 1px solid var(--line);
}
.btn.ghost:hover, summary.ghost:hover { border-color: var(--accent); }

/* inline-edit inputs that replace the display cells in edit mode */
.cell-input {
    padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px;
    font-size: 14px; color: var(--ink); background: #fff; width: 100%; max-width: 150px;
}

/* authorization-expiry cell */
.auth-warn { color: var(--warn-ink); font-weight: 600; }
.auth-note { display: block; font-size: 12px; color: var(--muted); }

/* Shopify token entry keeps its expandable form but its summary looks like a button */
.token-entry > summary { list-style: none; display: inline-block; cursor: pointer; }
.token-entry > summary::-webkit-details-marker { display: none; }
.token-entry[open] > .inline-form { margin-top: 8px; }

/* warning notice (auth reminder banner) */
.notice.warn {
    background: var(--warn-bg); color: var(--warn-ink); border: 1px solid #f0d097;
    border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; max-width: 1100px;
}

/* Shopee order-sync detailed log */
.sync-log {
    margin-top: 12px; padding: 12px 14px; max-height: 460px; overflow: auto;
    background: #0f172a; color: #e2e8f0; border-radius: 8px;
    font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap; word-break: break-word;
}

/* live sync progress counts strip */
.sync-counts {
    display: flex; flex-wrap: wrap; gap: 18px; margin: 4px 0 14px;
    font-size: 14px; color: var(--muted);
}
.sync-counts b { color: var(--ink); font-size: 16px; }
#liveTable td, #liveTable th { font-size: 13px; }
