/* ---------------------------------------------------------------------------
   Design tokens

   The app runs both standalone and inside a Zoho CRM iframe, which is often
   short and narrow, so the scale is compact and the layout never assumes a
   full browser window.
--------------------------------------------------------------------------- */
:root {
  --green: #0F9D58;
  --green-dark: #0B8043;
  --green-light: #E6F4EA;
  --ink: #1f2124;
  --ink-2: #3c4043;
  --muted: #5f6368;
  --line: #e3e6e8;
  --line-strong: #d3d7da;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --red: #c5221f;
  --red-light: #fce8e6;
  --amber: #b06000;
  --amber-light: #fef7e0;
  --blue: #1a73e8;

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(60,64,67,.10), 0 1px 3px rgba(60,64,67,.06);
  --shadow-lg: 0 4px 14px rgba(60,64,67,.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--green-dark); }
code {
  background: #f1f3f4; padding: 1px 5px; border-radius: 4px;
  font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------------------------------------------------------------- app bar */
.appbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.appbar .mark {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  background: var(--green); color: #fff;
  display: grid; place-items: center; font-size: 15px; flex: none;
}
.appbar h1 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.appbar .org { font-size: 12px; color: var(--muted); }
.appbar .spacer { flex: 1 1 auto; }
.appbar .chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ shell */
.wrap { max-width: 940px; margin: 20px auto 48px; padding: 0 16px; }
.wrap.narrow { max-width: 620px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card > h2 {
  margin: 0 0 2px; font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card > .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.card + .card { margin-top: 0; }

.section-label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  margin: 22px 0 10px;
}
.section-label:first-child { margin-top: 0; }

/* ------------------------------------------------------------------- tabs */
.tabs {
  display: flex; gap: 2px; margin-bottom: 18px; overflow-x: auto;
  border-bottom: 1px solid var(--line); padding-bottom: 0;
}
.tabs button {
  appearance: none; background: none; border: none; cursor: pointer;
  padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
  font-family: inherit;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--green-dark); border-bottom-color: var(--green); }
.tabs .count {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  background: #eceff1; border-radius: 999px; font-size: 11px; color: var(--muted);
}
.panel[hidden] { display: none; }

/* ------------------------------------------------------------------ pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.on { background: var(--green-light); color: var(--green-dark); }
.pill.off { background: var(--red-light); color: var(--red); }
.pill.warn { background: var(--amber-light); color: var(--amber); }
.pill.neutral { background: #eceff1; color: var(--muted); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ------------------------------------------------------------------ forms */
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; font-weight: 500; }
input[type=text], input[type=password], input[type=time], select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-light);
}
input:disabled, select:disabled { background: #f8f9fa; color: var(--muted); }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; min-width: 0; }

.check { display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; }
.check input { width: auto; margin-top: 3px; flex: none; }
.check label { margin: 0; font-size: 13px; color: var(--ink-2); }

.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 5px; }
.hint.error { color: var(--red); }

.module-picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 2px 14px; max-height: 230px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px;
}
.module-picker label.check { margin: 3px 0; }

.field-picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 2px 14px; max-height: 190px; overflow-y: auto; padding: 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 4px;
}
.field-picker label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 400; margin: 2px 0; color: var(--ink-2);
}

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--green); color: #fff; border: 1px solid var(--green);
  padding: 9px 16px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none; margin-top: 14px;
}
.btn:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn.ghost { background: #fff; color: var(--ink-2); border-color: var(--line-strong); }
.btn.ghost:hover { background: #f8f9fa; border-color: var(--muted); }
.btn.danger { background: #fff; color: var(--red); border-color: #f3c3c1; }
.btn.danger:hover { background: var(--red-light); }
.btn.small { padding: 5px 10px; font-size: 12px; margin-top: 0; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.btn-row .btn { margin-top: 0; }
.inline-form { display: inline-block; margin: 0 4px 0 0; }
.inline-form .btn { margin-top: 0; }

.spin {
  display: inline-block; width: 12px; height: 12px; margin-right: 7px;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff;
  border-radius: 50%; animation: btnspin .7s linear infinite; vertical-align: -2px;
}
.btn.ghost .spin, .btn.danger .spin { border-color: #dadce0; border-top-color: var(--muted); }
@keyframes btnspin { to { transform: rotate(360deg); } }
.is-busy { opacity: .6; pointer-events: none; }

/* -------------------------------------------------------------- messages */
.msg {
  padding: 11px 14px; border-radius: var(--r-sm); margin-bottom: 12px;
  font-size: 13px; border: 1px solid transparent;
}
.msg.success { background: var(--green-light); color: var(--green-dark); border-color: #ceead6; }
.msg.error, .msg.warning { background: var(--red-light); color: var(--red); border-color: #f5c6c4; }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--amber-light); border: 1px solid #fde293;
  color: var(--amber); font-size: 13px; margin-bottom: 16px;
}
.notice.info { background: #e8f0fe; border-color: #c6dafc; color: #174ea6; }
.notice .btn { margin-top: 8px; }

/* --------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 8px; font-size: 11px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.status-success { color: var(--green-dark); font-weight: 600; }
.status-failed { color: var(--red); font-weight: 600; }
.status-partial { color: var(--amber); font-weight: 600; }
.status-running { color: var(--blue); font-weight: 600; }

.nowrap { white-space: nowrap; }
.muted { color: var(--muted); font-size: 13px; }
.muted-inline { font-size: 12px; font-weight: 400; color: var(--muted); }

/* ------------------------------------------------------------- overview */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px 14px; background: #fbfcfc;
}
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.stat .v { font-size: 20px; font-weight: 600; margin-top: 4px; letter-spacing: -.02em; }
.stat .v.small { font-size: 14px; font-weight: 500; }

/* ---------------------------------------------------------------- setup */
.steps { counter-reset: step; }
.step-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 18px 20px; margin-bottom: 12px;
  box-shadow: var(--shadow); position: relative;
}
.step-card.done { background: #fbfdfc; }
.step-card.waiting { opacity: .62; }
.step-head { display: flex; align-items: center; gap: 10px; }
.step-num {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: #eceff1; color: var(--muted);
}
.step-card.current .step-num { background: var(--green); color: #fff; }
.step-card.done .step-num { background: var(--green-light); color: var(--green-dark); }
.step-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.step-body { margin-top: 12px; }

/* ------------------------------------------------------- rules & mapping */
.dest-table td { vertical-align: middle; }
.dest-table .mod { font-weight: 600; }
.rule-table td { vertical-align: top; }
.cond-cell div { margin-bottom: 3px; }
.pos {
  display: inline-block; min-width: 20px; padding: 1px 7px; margin-right: 7px;
  background: #eceff1; border-radius: 999px; font-size: 11px; color: var(--muted);
  font-weight: 600;
}
.condition-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.condition-row select, .condition-row input { flex: 1 1 0; min-width: 0; }
.condition-row .drop { flex: none; margin-top: 0; }
.inline-select { display: inline-block; width: auto; margin-left: 8px; }
.tab-select, .tab-new { max-width: 100%; }
.tab-new { margin-top: 6px; }
.tab-cell .btn { margin-top: 6px; }

details.disclose {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px 14px; margin-top: 14px; background: #fbfcfc;
}
details.disclose > summary {
  cursor: pointer; font-weight: 600; font-size: 13px; color: var(--green-dark);
  list-style: none;
}
details.disclose > summary::-webkit-details-marker { display: none; }
details.disclose > summary::before { content: '+ '; font-weight: 700; }
details.disclose[open] > summary::before { content: '\2212  '; }
details.disclose > form { margin-top: 14px; }

.empty {
  text-align: center; padding: 26px 16px; color: var(--muted);
  border: 1px dashed var(--line-strong); border-radius: var(--r-sm); font-size: 13px;
}

.pager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

@media (max-width: 620px) {
  .wrap { margin-top: 12px; padding: 0 12px; }
  .card { padding: 16px; }
  .appbar { padding: 10px 14px; }
}

/* --------------------------------------------------------- account menu */
.account { position: relative; }
.account > summary {
  cursor: pointer; list-style: none; font-size: 12px; font-weight: 600;
  color: var(--ink-2); padding: 3px 10px; border: 1px solid var(--line-strong);
  border-radius: 999px; background: #fff; max-width: 190px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.account > summary::-webkit-details-marker { display: none; }
.account > summary::after { content: ' BE'; color: var(--muted); }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30;
  width: 270px; padding: 14px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-lg);
}
.account-menu label:first-child { margin-top: 0; }
.account-menu .btn { width: 100%; }
.account-menu > .btn.ghost { margin-top: 10px; }
