/* SumUp Connector - giao diện. Navy + teal, nền sáng. Font hệ thống (CSP không cho font ngoài).
   Xem DESIGN.md. Class theo BEM, khớp views/. */

:root {
  --navy-900: #0b1f3a;
  --navy-800: #12305a;
  --navy-700: #1b4378;
  --teal-700: #0f766e;
  --teal-800: #115e59;
  --teal-100: #ccfbf1;
  --teal-50: #effcf9;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --border: #d7dfe9;
  --border-strong: #b6c3d4;
  --text: #14233a;
  --muted: #4b5d75;
  --ok-bg: #dcfce7; --ok-fg: #14532d;
  --warn-bg: #ffedd5; --warn-fg: #7c2d12;
  --err-bg: #fee2e2; --err-fg: #7f1d1d;
  --gray-bg: #e5eaf1; --gray-fg: #2f3e55;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(11, 31, 58, .06), 0 4px 14px rgba(11, 31, 58, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--font); color: var(--text); background: var(--bg); min-height: 100vh; }
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
a { color: var(--teal-800); text-underline-offset: 2px; }
a:hover { color: var(--navy-800); }
img, svg { max-width: 100%; }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; border-radius: 4px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; vertical-align: middle; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Header (app) ---------- */
.site-header { position: sticky; top: 0; z-index: 20; background: var(--navy-900); color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px; padding: 0 20px; min-height: 60px; box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
.site-header__brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.1rem; text-decoration: none; min-height: 44px; margin-right: auto; }
.site-header__brand:hover { color: #fff; }
.site-header__logo { width: 28px; height: 28px; padding: 5px; background: var(--teal-700); border-radius: 8px; color: #fff; }
.site-header__toggle { position: absolute; opacity: 0; width: 44px; height: 44px; right: 12px; top: 8px; margin: 0; cursor: pointer; z-index: 2; display: none; }
.site-header__burger { display: none; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid rgba(255, 255, 255, .35); cursor: pointer; font-weight: 600; }
.site-header__menu { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.site-nav__list { list-style: none; padding: 0; display: flex; gap: 4px; flex-wrap: wrap; }
.site-nav__link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; color: #dbe6f5; text-decoration: none; font-weight: 600; border-radius: var(--radius-sm); border-bottom: 3px solid transparent; }
.site-nav__link:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.site-nav__link--current { color: #fff; background: rgba(255, 255, 255, .12); border-bottom-color: #2dd4bf; }
.site-header__user { display: flex; align-items: center; gap: 10px; padding-left: 20px; border-left: 1px solid rgba(255, 255, 255, .22); }
.site-header__username { color: #fff; font-weight: 600; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.site-header__username:hover { text-decoration: underline; color: #fff; }
.site-header__role { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; background: rgba(45, 212, 191, .2); color: #99f6e4; padding: 2px 8px; border-radius: 999px; }
.site-header__logout { margin: 0; }
.site-header .button--link { color: #dbe6f5; }
.site-header .button--link:hover { color: #fff; background: rgba(255, 255, 255, .1); }

@media (max-width: 860px) {
  .site-header { padding: 6px 14px; }
  .site-header__toggle { display: block; }
  .site-header__burger { display: inline-flex; }
  .site-header__menu { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 8px; padding: 8px 0 14px; border-top: 1px solid rgba(255, 255, 255, .15); }
  .site-header__toggle:checked ~ .site-header__menu { display: flex; }
  .site-header__toggle:focus-visible ~ .site-header__burger { outline: 3px solid #f59e0b; outline-offset: 2px; }
  .site-nav__list { flex-direction: column; }
  .site-nav__link { width: 100%; border-bottom: 0; border-left: 3px solid transparent; }
  .site-nav__link--current { border-left-color: #2dd4bf; }
  .site-header__user { padding-left: 0; border-left: 0; border-top: 1px solid rgba(255, 255, 255, .15); padding-top: 10px; flex-wrap: wrap; }
}

/* ---------- Layout ---------- */
.site-main { max-width: 1240px; margin: 0 auto; padding: 28px 20px 56px; display: flex; flex-direction: column; gap: 20px; }
.page-title { font-size: 1.65rem; line-height: 1.25; color: var(--navy-900); letter-spacing: -.01em; }
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; }
.breadcrumb { color: var(--muted); font-size: .9rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel__title { font-size: 1.1rem; color: var(--navy-900); }
.panel__lead { color: var(--muted); }
.notice { background: #fff7e0; border: 1px solid #f3d27a; color: #5c4300; border-radius: var(--radius-sm); padding: 12px 14px; }
.empty-state { text-align: center; color: var(--muted); padding: 32px 16px; border: 2px dashed var(--border); border-radius: var(--radius); background: #fafcfe; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty-state__icon { width: 44px; height: 44px; color: var(--navy-700); opacity: .55; }
.empty-state p:first-of-type { color: var(--text); font-weight: 600; }
.empty-state__hint { font-size: .95rem; }

/* ---------- Buttons ---------- */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; font: inherit; font-weight: 600; color: var(--navy-900); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, box-shadow .15s; }
.button:hover { background: #eef3f9; border-color: var(--navy-700); color: var(--navy-900); }
.button:active { transform: translateY(1px); }
.button[disabled] { opacity: .6; cursor: progress; }
.button--primary { background: var(--teal-700); border-color: var(--teal-700); color: #fff; box-shadow: 0 1px 2px rgba(15, 118, 110, .35); }
.button--primary:hover { background: var(--teal-800); border-color: var(--teal-800); color: #fff; }
.button--danger { background: #fff; color: #991b1b; border-color: #e0a3a3; }
.button--danger:hover { background: #fee2e2; border-color: #991b1b; color: #7f1d1d; }
.button--link { background: transparent; border-color: transparent; padding: 0 12px; color: var(--teal-800); }
.button--link:hover { background: rgba(15, 118, 110, .08); border-color: transparent; }
.button--copy { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.button--copy:hover { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }
.button--copy.button--done { background: var(--teal-700); border-color: var(--teal-700); }
.button--export { background: var(--teal-50); border-color: #7cd6c9; color: var(--teal-800); }
.button--export:hover { background: var(--teal-100); border-color: var(--teal-700); color: var(--teal-800); }
.button--large { min-height: 64px; font-size: 1.2rem; width: 100%; border-radius: var(--radius); }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; max-width: 560px; }
.form .button { align-self: flex-start; }
.form__field { display: flex; flex-direction: column; gap: 6px; }
.form__label, .filter-form__label, .search-form__label { font-weight: 600; font-size: .92rem; color: var(--navy-900); }
.form__required { color: #b91c1c; font-weight: 700; }
.form__saved { color: var(--muted); font-size: .9rem; }
.form__input, .form__textarea, .form__select, .filter-form__input, .filter-form__select, .search-form__input, .copy-field__input, .flash__link-input {
  font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); min-height: 44px; padding: 8px 12px; width: 100%; min-width: 0; }
.form__textarea { resize: vertical; }
.form__input:hover, .form__textarea:hover, .form__select:hover { border-color: var(--navy-700); }
.form__input:focus, .form__textarea:focus, .form__select:focus, .filter-form__input:focus, .filter-form__select:focus, .search-form__input:focus { outline: 3px solid rgba(15, 118, 110, .35); border-color: var(--teal-700); }
.form__input::placeholder { color: #66768d; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }
.inline-form .form__input { min-width: 160px; }

.panel--create-customer { border-top: 4px solid var(--teal-700); }
.panel--create-customer .form { max-width: 720px; }

.search-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search-form__label { flex-basis: 100%; }
.search-form__input { flex: 1 1 220px; max-width: 360px; }

/* ---------- Flash + link box ---------- */
.flash { border-radius: var(--radius); padding: 16px 18px; border: 1px solid; display: flex; flex-direction: column; gap: 12px; }
.flash--ok { background: var(--teal-50); border-color: #7cd6c9; color: #0b4a45; }
.flash--error { background: var(--err-bg); border-color: #f0a5a5; color: var(--err-fg); }
.flash__message { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; }
.flash__message .icon { margin-top: 2px; }
.flash__link { background: #fff; border: 2px solid var(--teal-700); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 6px 20px rgba(15, 118, 110, .18); color: var(--text); }
.flash__link-label { font-weight: 700; color: var(--navy-900); }
.flash__link-input { font-family: var(--mono); font-size: .95rem; background: var(--teal-50); border-color: #7cd6c9; }
.flash__hint { display: flex; gap: 8px; align-items: flex-start; background: var(--warn-bg); color: var(--warn-fg); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .92rem; }
.flash__hint .icon { margin-top: 2px; }
.copy-field { display: flex; gap: 8px; align-items: stretch; }
.copy-field__input { font-family: var(--mono); font-size: .95rem; flex: 1; }
.copy-field .button { flex: none; }

/* ---------- Status badges ---------- */
.status-badge, .tx-status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700; line-height: 1.4; white-space: nowrap; background: var(--gray-bg); color: var(--gray-fg); }
.status-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-badge--pending { background: var(--gray-bg); color: var(--gray-fg); }
.status-badge--connected { background: var(--ok-bg); color: var(--ok-fg); }
.status-badge--reauth_needed { background: var(--warn-bg); color: var(--warn-fg); }
.status-badge--revoked { background: var(--err-bg); color: var(--err-fg); }
.status-badge--expired { background: #f1f1f1; color: #3d3d3d; text-decoration: line-through; text-decoration-thickness: 1.5px; }
.tx-status { font-size: .78rem; padding: 2px 9px; text-transform: capitalize; }
.tx-status--successful, .tx-status--paidout { background: var(--ok-bg); color: var(--ok-fg); }
.tx-status--failed, .tx-status--cancelled, .tx-status--refunded, .tx-status--chargeback { background: var(--err-bg); color: var(--err-fg); }
.tx-status--pending { background: var(--warn-bg); color: var(--warn-fg); }

.status-counters { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.status-counters__item { display: inline-flex; align-items: center; gap: 10px; background: #f7f9fc; border: 1px solid var(--border); border-radius: 999px; padding: 6px 8px 6px 8px; }
.status-counters__count { min-width: 28px; text-align: center; font-weight: 800; font-size: 1.05rem; color: var(--navy-900); padding-right: 6px; }

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
thead th { background: #eef3f9; color: var(--navy-800); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: #f7fafd; }
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table-wrap table { margin: 0; }
tbody tr:last-child td { border-bottom: 0; }
.customer-row__name a { font-weight: 700; }
.customer-row__tx-count, .transaction-row__amount, .transactions-table__amount { text-align: right; font-variant-numeric: tabular-nums; }
.transaction-row__amount { font-weight: 700; white-space: nowrap; }
.transaction-row__code, .customer-row__merchant { font-family: var(--mono); font-size: .86rem; }
.transaction-row__time, .customer-row__last-sync, .customer-row__created { white-space: nowrap; }
.transaction-row__description { min-width: 160px; }
.customer-row__actions .button { min-height: 36px; padding: 0 12px; font-size: .88rem; }
.customer-row__actions form { margin: 0; }

/* ---------- Customer detail ---------- */
.info-list { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; }
.info-list dd { min-width: 0; overflow-wrap: anywhere; }
.info-list > dt { display: block; color: var(--muted); font-size: .9rem; font-weight: 600; }
.info-list > dd { font-weight: 500; }
.info-list__last-sync { font-weight: 700 !important; color: var(--navy-900); }
.info-list__error { color: var(--err-fg); background: var(--err-bg); padding: 4px 10px; border-radius: 6px; }
@media (min-width: 900px) { .info-list { grid-template-columns: max-content 1fr max-content 1fr; } }
.action-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding-top: 6px; border-top: 1px solid var(--border); }
.action-bar form { margin: 0; }
.action-bar .button--primary { min-height: 52px; padding: 0 28px; font-size: 1.05rem; }
.panel--customer-info { border-top: 4px solid var(--navy-800); }

.filter-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filter-form__field { display: flex; flex-direction: column; gap: 6px; min-width: 160px; }
.filter-form__note { flex-basis: 100%; color: var(--muted); font-size: .85rem; }
.quick-range { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; flex-basis: 100%; }
.quick-range__link { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-strong); background: #fff; color: var(--navy-800); text-decoration: none; font-weight: 600; font-size: .9rem; }
.quick-range__link:hover { background: var(--teal-50); border-color: var(--teal-700); color: var(--teal-800); }
.result-summary { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; font-weight: 600; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; flex-wrap: wrap; }
.pager__link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); text-decoration: none; font-weight: 600; background: #fff; }
.pager__link:hover { background: var(--teal-50); border-color: var(--teal-700); }
.pager__info { color: var(--muted); }

/* ---------- Settings ---------- */
.panel--redirect-url { border-top: 4px solid var(--teal-700); background: linear-gradient(180deg, var(--teal-50), #fff 60%); }
.panel--redirect-url .copy-field__input { background: #fff; font-weight: 600; }
.steps { list-style: none; padding: 0; counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.steps > li { counter-increment: step; position: relative; padding-left: 40px; min-height: 28px; }
.steps > li::before { content: counter(step); flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--navy-800); color: #fff; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-size: .9rem; position: absolute; left: 0; top: 0; }
.panel--sumup-settings .form { max-width: 560px; }

/* ---------- Public: login + customer ---------- */
.public-header { display: flex; justify-content: center; padding: 22px 16px 6px; }
.public-header__brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: var(--navy-900); }
.public-header__logo { width: 36px; height: 36px; padding: 7px; background: var(--navy-900); color: #5eead4; border-radius: 10px; }
.public-main { max-width: 520px; margin: 0 auto; padding: 16px 16px 48px; }
.public--login, .public--landing, .public--message, [class*="public--status"] { background: linear-gradient(180deg, #e7eef8 0, var(--bg) 280px); }

.auth-card, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 10px 30px rgba(11, 31, 58, .1); padding: 28px 24px; display: flex; flex-direction: column; gap: 18px; }
.auth-card__title, .card__title { font-size: 1.6rem; line-height: 1.25; color: var(--navy-900); }
.auth-card__sub { color: var(--muted); margin-top: -10px; }
.auth-card .form { max-width: none; }
.auth-card .form .button { align-self: stretch; }

.card--landing, .card--status { align-items: center; text-align: center; }
.card__badge, .card__icon { width: 72px; height: 72px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--teal-50); color: var(--teal-700); }
.card__badge .icon { width: 36px; height: 36px; }
.card__icon .icon { width: 40px; height: 40px; stroke-width: 2.4; }
.card__icon--ok { width: 96px; height: 96px; background: var(--ok-bg); color: #15803d; }
.card__icon--ok .icon { width: 56px; height: 56px; stroke-width: 2.8; }
.card__icon--info { background: var(--teal-50); color: var(--teal-700); }
.card__icon--warn { background: var(--warn-bg); color: #b45309; }
.card__icon--error { background: var(--err-bg); color: #b91c1c; }
.card__intro, .card__text { font-size: 1.05rem; color: var(--muted); }
.card__points { list-style: none; padding: 0; width: 100%; text-align: left; background: #f6f9fd; border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; }
.card__point { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; }
.card__point + .card__point { border-top: 1px solid var(--border); }
.card__point .icon { color: var(--teal-700); margin-top: 3px; width: 22px; height: 22px; }
.card__form { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.card__hint { color: var(--muted); font-size: .95rem; }
.card__browser-hint { color: var(--muted); font-size: .85rem; }
.card__actions { width: 100%; }
.card__actions .button { width: 100%; min-height: 52px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .site-main { padding: 18px 14px 40px; gap: 16px; }
  .page-title { font-size: 1.4rem; }
  .panel { padding: 16px; }
  .form { max-width: none; }
  .form .button, .filter-form .button, .search-form .button { align-self: stretch; width: 100%; }
  .filter-form__field { flex: 1 1 140px; }
  .copy-field { flex-direction: column; }
  .copy-field .button { width: 100%; }
  .action-bar .button, .action-bar form { width: 100%; }
  .action-bar .button--primary { width: 100%; }
  .search-form__input { max-width: none; }
  .auth-card, .card { padding: 24px 18px; }

  /* Bảng -> thẻ */
  .table-wrap { border: 0; overflow: visible; }
  .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td { display: block; width: 100%; }
  .responsive-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .responsive-table tr { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; padding: 6px 14px; box-shadow: var(--shadow); }
  .responsive-table td { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 9px 0; border-bottom: 1px solid #edf1f6; text-align: right; overflow-wrap: anywhere; }
  .responsive-table td:last-child { border-bottom: 0; }
  .responsive-table td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: .82rem; font-weight: 600; text-align: left; }
  .responsive-table td:not([data-label])::before { content: none; }
  .responsive-table td:empty { display: none; }
  .responsive-table td:first-child:not([data-label]) { font-size: 1.05rem; justify-content: flex-start; text-align: left; }
  .customer-row__actions { justify-content: stretch !important; }
  .customer-row__actions form, .customer-row__actions .button { width: 100%; min-height: 44px; }
  .transaction-row__amount { font-size: 1.05rem; }
  .inline-form { flex-wrap: wrap; width: 100%; }
  .inline-form .form__input { flex: 1 1 100%; }
  .inline-form .button { width: 100%; }
  .transactions-table .transaction-row__time { font-weight: 700; justify-content: flex-start; text-align: left; }
  .customer-row__tx-count { text-align: right; }

  /* Giao dịch: thẻ gọn 2 cột */
  .transactions-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; padding: 10px 14px; }
  .transactions-table td { display: block; text-align: left; border-bottom: 0; padding: 5px 0; }
  .transactions-table td::before { display: block; margin-bottom: 1px; font-size: .74rem; }
  .transactions-table .transaction-row__time, .transactions-table .transaction-row__description, .transactions-table .transaction-row__customer { grid-column: 1 / -1; }
  .transactions-table .transaction-row__time { padding-bottom: 8px; border-bottom: 1px solid #edf1f6; margin-bottom: 4px; }
  .transactions-table .transaction-row__amount { text-align: left; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .site-header, .action-bar, .pager { display: none; } }
