/* RNPilot base styles.
 *
 * Everything here lives in the "rn-base" cascade layer, so any rule in custom.css
 * (which is not layered) overrides it regardless of selector specificity.
 * Tweak colors/sizes via the CSS variables below — redefine them in custom.css.
 */
@layer rn-base {
  :root {
    --rn-primary: #cb11ab;
    --rn-primary-dark: #481173;
    --rn-primary-soft: #f8e7f5;
    --rn-gradient: linear-gradient(135deg, #cb11ab 0%, #7a1b9c 55%, #481173 100%);
    --rn-bg: #f6f4fa;
    --rn-surface: #ffffff;
    --rn-surface-alt: #faf8fc;
    --rn-border: #ece8f2;
    --rn-text: #1c1a24;
    --rn-text-muted: #8a8598;
    --rn-pos: #1b8a4c;
    --rn-pos-bg: #e5f6ec;
    --rn-neg: #d9254e;
    --rn-neg-bg: #fde8ed;
    --rn-warning-bg: #fff5e0;
    --rn-warning: #9a6200;
    --rn-info-bg: #eef0ff;
    --rn-radius: 16px;
    --rn-radius-sm: 10px;
    --rn-shadow: 0 1px 2px rgba(40, 20, 60, 0.04), 0 4px 16px rgba(40, 20, 60, 0.05);
    --rn-font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --rn-gutter: 24px;
    --rn-topbar-h: 64px;
  }

  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0;
    font-family: var(--rn-font);
    font-size: 14px;
    line-height: 1.45;
    color: var(--rn-text);
    background: var(--rn-bg);
    -webkit-font-smoothing: antialiased;
  }
  body.rn-modal-open { overflow: hidden; }
  a { color: var(--rn-primary); text-decoration: none; }
  a:hover { text-decoration: underline; }
  h1, h2, h3 { margin: 0; line-height: 1.2; }
  button, input, textarea, select { font: inherit; color: inherit; }
  [hidden] { display: none !important; }

  .rn-muted { color: var(--rn-text-muted); }
  .rn-text-error { color: var(--rn-neg); }
  .rn-required { color: var(--rn-neg); }

  /* ---------- layout ---------- */
  .rn-main { max-width: 1200px; margin: 0 auto; padding: var(--rn-gutter); }
  .rn-main--wide { max-width: none; }
  .rn-page__title { font-size: 26px; font-weight: 800; margin: 8px 0 24px; }
  .rn-card {
    background: var(--rn-surface);
    border: 1px solid var(--rn-border);
    border-radius: var(--rn-radius);
    box-shadow: var(--rn-shadow);
  }

  /* ---------- topbar ---------- */
  .rn-topbar {
    position: sticky; top: 0; z-index: 50;
    height: var(--rn-topbar-h);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(1.5) blur(10px);
    border-bottom: 1px solid var(--rn-border);
  }
  .rn-topbar__inner {
    height: 100%; display: flex; align-items: center; justify-content: space-between;
    padding: 0 var(--rn-gutter);
  }
  .rn-topbar__right { display: flex; align-items: center; gap: 6px; }
  .rn-topbar__user { font-weight: 600; margin-right: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
  .rn-topbar__logout-form { margin: 0; }
  .rn-topbar__btn, .rn-icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid var(--rn-border); background: var(--rn-surface);
    color: var(--rn-text); cursor: pointer; transition: .15s;
  }
  .rn-topbar__btn:hover, .rn-icon-btn:hover { color: var(--rn-primary); border-color: var(--rn-primary); text-decoration: none; }

  .rn-logo { display: inline-flex; align-items: center; gap: 10px; color: var(--rn-text); }
  .rn-logo:hover { text-decoration: none; }
  .rn-logo__text {
    font-weight: 800; font-size: 20px; letter-spacing: -0.02em;
    background: var(--rn-gradient); -webkit-background-clip: text; background-clip: text; color: transparent;
  }
  .rn-logo--large .rn-logo__text { font-size: 34px; }

  /* ---------- controls ---------- */
  .rn-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 42px; padding: 0 18px; border-radius: var(--rn-radius-sm);
    border: 1px solid transparent; font-weight: 700; cursor: pointer;
    transition: .15s; white-space: nowrap; text-decoration: none;
  }
  .rn-btn:hover { text-decoration: none; }
  .rn-btn .rn-icon { width: 18px; height: 18px; }
  .rn-btn--primary { background: var(--rn-gradient); color: #fff; }
  .rn-btn--primary:hover { filter: brightness(1.08); }
  .rn-btn--secondary { background: var(--rn-primary-soft); color: var(--rn-primary-dark); }
  .rn-btn--secondary:hover { background: #f1d6ec; }
  .rn-btn--danger { background: var(--rn-neg-bg); color: var(--rn-neg); }
  .rn-btn--danger:hover { background: #fbd3dd; }
  .rn-btn--block { width: 100%; }
  .rn-btn--xs { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; }

  .rn-link { font-weight: 600; }
  .rn-link-btn { background: none; border: 0; padding: 0; color: var(--rn-primary); font-weight: 700; cursor: pointer; }

  .rn-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
  .rn-field__label { font-size: 13px; font-weight: 600; color: var(--rn-text-muted); }
  .rn-input {
    width: 100%; height: 44px; padding: 0 14px;
    border: 1px solid var(--rn-border); border-radius: var(--rn-radius-sm);
    background: var(--rn-surface); outline: none; transition: .15s;
  }
  .rn-input:focus { border-color: var(--rn-primary); box-shadow: 0 0 0 3px rgba(203, 17, 171, 0.12); }
  .rn-input:disabled { background: var(--rn-surface-alt); color: var(--rn-text-muted); }
  .rn-textarea { height: auto; padding: 12px 14px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
  .rn-input--sm { height: 34px; padding: 0 10px; width: 84px; border-radius: 8px; font-size: 13px; }
  .rn-input--invalid { border-color: var(--rn-neg); }
  .rn-input--saved { border-color: var(--rn-pos); box-shadow: 0 0 0 3px rgba(27, 138, 76, 0.15); }

  .rn-check { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }
  .rn-check input { width: 17px; height: 17px; accent-color: var(--rn-primary); }
  .rn-fieldset { border: 1px solid var(--rn-border); border-radius: var(--rn-radius-sm); padding: 12px 16px; margin: 0; min-width: 0; }
  .rn-fieldset__legend { font-weight: 700; padding: 0 6px; }

  .rn-chip {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px; padding: 0 14px; border-radius: 999px;
    border: 1px solid var(--rn-border); background: var(--rn-surface);
    font-size: 13px; font-weight: 600; cursor: pointer; transition: .15s;
  }
  .rn-chip:hover { border-color: var(--rn-primary); color: var(--rn-primary); }
  .rn-chip--active, .rn-chip--active:hover { background: var(--rn-gradient); border-color: transparent; color: #fff; }
  .rn-chip--icon { width: 34px; padding: 0; }
  .rn-chip .rn-icon { width: 17px; height: 17px; }

  .rn-badge {
    display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px;
    background: var(--rn-surface-alt); border: 1px solid var(--rn-border); font-size: 12px; font-weight: 600;
  }
  .rn-badge--primary { background: var(--rn-primary-soft); border-color: transparent; color: var(--rn-primary-dark); }
  .rn-badge--muted { color: var(--rn-text-muted); }
  .rn-badge--ok { background: var(--rn-pos-bg); border-color: transparent; color: var(--rn-pos); }
  .rn-badge--warning { background: var(--rn-warning-bg); border-color: transparent; color: var(--rn-warning); }
  .rn-badge--error { background: var(--rn-neg-bg); border-color: transparent; color: var(--rn-neg); }

  .rn-alert { padding: 12px 16px; border-radius: var(--rn-radius-sm); margin-bottom: 16px; font-weight: 500; }
  .rn-alert--error { background: var(--rn-neg-bg); color: var(--rn-neg); }
  .rn-alert--warning { background: var(--rn-warning-bg); color: var(--rn-warning); }
  .rn-alert--info { background: var(--rn-info-bg); color: #3a3f8f; }

  .rn-flashes { margin-bottom: 16px; }
  .rn-flash { padding: 12px 16px; border-radius: var(--rn-radius-sm); margin-bottom: 8px; font-weight: 600; }
  .rn-flash--ok { background: var(--rn-pos-bg); color: var(--rn-pos); }
  .rn-flash--error { background: var(--rn-neg-bg); color: var(--rn-neg); }

  .rn-backlink { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; }
  .rn-backlink .rn-icon { width: 16px; height: 16px; }
  .rn-empty { color: var(--rn-text-muted); padding: 24px 0; }

  /* ---------- tooltip, toast, modal ---------- */
  .rn-tooltip {
    position: fixed; z-index: 1000; max-width: 320px; pointer-events: none;
    padding: 8px 12px; border-radius: 8px; background: #231d2e; color: #fff;
    font-size: 12px; font-weight: 500; line-height: 1.4; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  }
  .rn-toasts { position: fixed; right: 20px; bottom: 20px; z-index: 1100; display: flex; flex-direction: column; gap: 8px; }
  .rn-toast {
    padding: 12px 18px; border-radius: 12px; background: #231d2e; color: #fff; font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); transition: opacity .3s, transform .3s;
  }
  .rn-toast--error { background: var(--rn-neg); }
  .rn-toast--hide { opacity: 0; transform: translateY(8px); }

  .rn-modal { position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center; padding: 16px; }
  .rn-modal__backdrop { position: absolute; inset: 0; background: rgba(28, 16, 40, 0.45); }
  .rn-modal__dialog { position: relative; width: 100%; max-width: 420px; padding: 28px; }
  .rn-modal__title { font-size: 20px; font-weight: 800; margin-bottom: 20px; }
  .rn-modal__close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border: 0; }

  /* ---------- tables ---------- */
  .rn-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .rn-table { width: 100%; border-collapse: collapse; }
  .rn-table th {
    text-align: left; font-size: 12px; font-weight: 700; color: var(--rn-text-muted);
    padding: 14px 12px; border-bottom: 1px solid var(--rn-border); white-space: nowrap;
  }
  .rn-table td { padding: 12px; border-bottom: 1px solid var(--rn-border); vertical-align: middle; }
  .rn-table tbody tr:nth-child(even) { background: var(--rn-surface-alt); }
  .rn-table tbody tr:last-child td { border-bottom: 0; }
  .rn-table--compact td, .rn-table--compact th { padding: 8px 10px; }

  /* ---------- login ---------- */
  .rn-body--login { background: radial-gradient(1200px 600px at 50% -10%, #f3d5ee 0%, var(--rn-bg) 60%); }
  .rn-login { min-height: calc(100vh - 2 * var(--rn-gutter)); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; }
  .rn-login__form { width: 100%; max-width: 380px; padding: 32px; }
  .rn-login__title { font-size: 22px; font-weight: 800; margin-bottom: 20px; }
  .rn-login__submit { margin-top: 8px; }

  /* ---------- tiles (modules, stores) ---------- */
  .rn-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
  .rn-tile {
    position: relative; display: flex; flex-direction: column; gap: 10px;
    padding: 24px; min-height: 170px;
    background: var(--rn-surface); border: 1px solid var(--rn-border); border-radius: var(--rn-radius);
    box-shadow: var(--rn-shadow); color: var(--rn-text); transition: transform .15s, box-shadow .15s, border-color .15s;
  }
  .rn-tile:hover { text-decoration: none; transform: translateY(-2px); border-color: #e6c3de; box-shadow: 0 10px 30px rgba(120, 20, 110, 0.12); }
  .rn-tile__icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 48px; height: 48px; border-radius: 14px; background: var(--rn-gradient); color: #fff;
  }
  .rn-tile__icon .rn-icon { width: 24px; height: 24px; }
  .rn-tile__title { font-size: 17px; font-weight: 800; }
  .rn-tile__text { color: var(--rn-text-muted); font-size: 13px; }
  .rn-tile--disabled { opacity: .65; }
  .rn-tile--disabled .rn-tile__icon { background: #cfc8da; }
  .rn-module-tile__soon { position: absolute; top: 20px; right: 20px; }
  .rn-stores .rn-backlink, .rn-soon .rn-backlink, .rn-admin .rn-backlink { margin-bottom: 4px; }

  /* ---------- error page ---------- */
  .rn-error { text-align: center; padding-top: 10vh; }
  .rn-error__code { font-size: 72px; font-weight: 800; background: var(--rn-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
  .rn-error__message { color: var(--rn-text-muted); margin-bottom: 24px; }

  /* ---------- admin ---------- */
  .rn-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rn-border); margin-bottom: 20px; overflow-x: auto; }
  .rn-tabs__item { padding: 10px 16px; font-weight: 700; color: var(--rn-text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
  .rn-tabs__item:hover { color: var(--rn-text); text-decoration: none; }
  .rn-tabs__item--active { color: var(--rn-primary); border-bottom-color: var(--rn-primary); }
  .rn-toolbar { display: flex; justify-content: flex-end; margin-bottom: 16px; }
  .rn-users__row--inactive td { opacity: .55; }
  .rn-users__role { display: flex; gap: 6px; flex-wrap: wrap; }
  .rn-users__actions { text-align: right; }

  .rn-form { padding: 28px; max-width: 760px; margin-bottom: 16px; }
  .rn-form__title { font-size: 19px; font-weight: 800; margin-bottom: 20px; }
  .rn-form__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
  .rn-form__grid .rn-field:last-child { grid-column: 1 / -1; }
  .rn-form__checks { margin-bottom: 16px; }
  .rn-form__columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .rn-form__hint { font-size: 13px; margin: 12px 0 0; }
  .rn-form__actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
  .rn-danger-zone { max-width: 760px; }

  .rn-store-admin { padding: 20px 24px; margin-bottom: 16px; }
  .rn-store-admin__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
  .rn-store-admin__name { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
  .rn-store-admin__token { font-size: 12px; font-family: ui-monospace, Menlo, monospace; }
  .rn-store-admin__actions { display: flex; gap: 8px; flex-wrap: wrap; }
  .rn-store-admin__actions form { margin: 0; }
  .rn-sync-table__message { font-size: 12px; max-width: 420px; word-break: break-word; }
  .rn-settings-refresh__text { margin: 0 0 16px; }

  /* ---------- unit economics ---------- */
  .rn-ue { display: flex; flex-direction: column; gap: 20px; }
  .rn-ue > .rn-alert { margin: 0; }
  .rn-ue-header {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
    padding: 20px 24px;
  }
  .rn-ue-header__left { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .rn-ue-header__title { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; overflow-wrap: anywhere; }
  .rn-ue-header__period { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .rn-ue-period-badge {
    display: inline-flex; align-items: center; height: 26px; padding: 0 12px; border-radius: 999px;
    background: var(--rn-gradient); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .02em;
  }
  .rn-ue-period-note { font-size: 12px; color: var(--rn-warning); font-weight: 600; cursor: help; }
  .rn-ue-period-note--live { color: var(--rn-pos); }
  .rn-ue-header__right { justify-self: end; }

  .rn-ue-capital {
    display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 16px;
    border-radius: 999px; background: var(--rn-gradient); color: #fff; font-weight: 700; white-space: nowrap;
  }
  .rn-ue-capital__value { background: #fff; color: var(--rn-primary); border: 0; border-radius: 999px; padding: 3px 10px; font-weight: 800; font-size: 13px; }
  .rn-ue-capital__qty { cursor: pointer; transition: .15s; }
  .rn-ue-capital__qty:hover { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35); }
  .rn-ue-capital--loading .rn-ue-capital__qty { animation: rn-pulse 1.2s ease-in-out infinite; cursor: progress; }
  @keyframes rn-pulse { 50% { opacity: .45; } }

  .rn-ue-periods { position: relative; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  .rn-ue-periods__picker { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; pointer-events: none; }

  .rn-ue-stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
  .rn-ue-stats--today { grid-template-columns: repeat(2, minmax(0, 240px)); }
  .rn-stat { padding: 16px 18px; }
  .rn-stat__label { font-size: 12px; color: var(--rn-text-muted); margin-bottom: 6px; }
  .rn-stat__value { font-size: 20px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .rn-stat__value--pos { color: var(--rn-pos); }
  .rn-stat__value--neg { color: var(--rn-neg); }

  .rn-ue-table-card { position: relative; overflow: hidden; }
  .rn-ue-table { min-width: 1280px; }
  .rn-ue-table td { white-space: nowrap; }
  .rn-ue-table__th--sortable { cursor: pointer; user-select: none; }
  .rn-ue-table__th--sortable:hover { color: var(--rn-text); }
  .rn-ue-table__th--sorted { color: var(--rn-primary); }
  .rn-ue-table__th--desc::after { content: " ↓"; }
  .rn-ue-table__th--asc::after { content: " ↑"; }
  .rn-ue-table .rn-col-photo { width: 64px; padding-top: 8px; padding-bottom: 8px; }
  .rn-ue-table .rn-col-title { font-weight: 700; }

  .rn-ue-photo { display: block; width: 44px; height: 58px; border-radius: 8px; overflow: hidden; background: var(--rn-surface-alt); }
  .rn-ue-photo__img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .rn-ue-photo__empty { display: block; width: 100%; height: 100%; background: repeating-linear-gradient(45deg, #f1edf5, #f1edf5 6px, #f8f5fa 6px, #f8f5fa 12px); }
  .rn-ue-title { cursor: default; }

  .rn-ue-profit { display: inline-flex; padding: 4px 10px; border-radius: 8px; font-weight: 800; cursor: default; }
  .rn-ue-profit--pos { background: var(--rn-pos-bg); color: var(--rn-pos); }
  .rn-ue-profit--neg { background: var(--rn-neg-bg); color: var(--rn-neg); }

  .rn-ue-cost { display: flex; align-items: center; gap: 6px; }
  .rn-ue-sku {
    display: inline-flex; padding: 3px 10px; border-radius: 999px;
    background: var(--rn-primary-soft); color: var(--rn-primary-dark); font-size: 13px; font-weight: 600;
  }
  .rn-ue-orders {
    display: inline-flex; padding: 4px 10px; border-radius: 8px;
    background: var(--rn-primary-soft); color: var(--rn-primary-dark); font-weight: 800;
  }
  .rn-ue-table--today { min-width: 720px; }
  .rn-ue-two { display: flex; flex-direction: column; line-height: 1.25; }
  .rn-ue-two__sub { font-size: 11px; color: var(--rn-text-muted); }

  .rn-ue-empty, .rn-ue-loading { padding: 40px; text-align: center; color: var(--rn-text-muted); }
  .rn-ue-loading { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.7); display: flex; align-items: center; justify-content: center; font-weight: 600; }

  /* ---------- responsive ---------- */
  @media (max-width: 1100px) {
    .rn-ue-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .rn-ue-header { grid-template-columns: 1fr auto; }
    .rn-ue-header__center { grid-column: 1 / -1; grid-row: 2; }
    .rn-ue-header__right { grid-column: 2; grid-row: 1; align-self: start; }
  }
  @media (max-width: 720px) {
    :root { --rn-gutter: 16px; }
    .rn-page__title { font-size: 22px; }
    .rn-ue-header { padding: 16px; }
    .rn-ue-header__title { font-size: 26px; }
    .rn-ue-stats, .rn-ue-stats--today { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .rn-stat__value { font-size: 17px; }
    .rn-ue-capital { flex-wrap: wrap; white-space: normal; border-radius: 16px; }
    .rn-form { padding: 20px; }
    .rn-form__grid, .rn-form__columns { grid-template-columns: 1fr; }
    .rn-topbar__user { max-width: 36vw; font-size: 13px; }
    .rn-logo__text { font-size: 18px; }
    .rn-tiles { grid-template-columns: 1fr; }
    .rn-tile { min-height: 0; }
  }

}

/* flatpickr accents: outside the layer, because flatpickr.css itself is not layered */
.flatpickr-day.selected, .flatpickr-day.startRange, .flatpickr-day.endRange,
.flatpickr-day.selected:hover, .flatpickr-day.startRange:hover, .flatpickr-day.endRange:hover {
  background: var(--rn-primary); border-color: var(--rn-primary);
}
.flatpickr-day.inRange { background: var(--rn-primary-soft); border-color: var(--rn-primary-soft); box-shadow: -5px 0 0 var(--rn-primary-soft), 5px 0 0 var(--rn-primary-soft); }
