/* AICallMe Console - design system. Orange brand, warm light background, white cards. */
:root {
  --brand: #F26B1D; --brand-2: #E8590C; --brand-soft: #FFF1E8; --brand-soft-2: #FFE2CF;
  --ink: #2B2622; --ink-2: #6A625C; --ink-3: #9C938B; --line: #EEE7E1; --bg: #FAF7F4; --card: #fff;
  --ok: #15803D; --ok-bg: #E7F6EC; --warn: #B45309; --warn-bg: #FFF2DC; --off: #6B7280; --off-bg: #F0EEEB; --err: #C62828; --err-bg: #FDECEC;
  --blue: #2F6FED; --blue-bg: #E8F0FE; --amber: #C77D00; --amber-bg: #FFF3D1;
  --radius: 16px; --shadow: 0 1px 2px rgba(60, 30, 10, .05), 0 8px 22px rgba(60, 30, 10, .045);
  --side-w: 244px; --tab-h: 64px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; line-break: strict; word-break: auto-phrase; overflow-wrap: break-word; }
h1, h2 { margin: 0; line-height: 1.3; }
p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid rgba(242, 107, 29, .45); outline-offset: 2px; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--ink-2); font-size: 14px; }
.only-m { display: none; }
.t-short { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- buttons / forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent; font-weight: 700; cursor: pointer; text-decoration: none; transition: background .15s, box-shadow .15s; white-space: nowrap; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(242, 107, 29, .28); }
.btn-primary:hover:not(:disabled) { background: var(--brand-2); }
.btn-ghost { background: #fff; border-color: #E2D9D1; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13.5px; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 8px 0; color: var(--brand); font-weight: 600; cursor: pointer; }
.link:disabled { color: var(--ink-3); cursor: default; }
.field { display: grid; gap: 6px; margin: 16px 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field input, .field select { width: 100%; min-height: 46px; padding: 0 14px; border: 1px solid #E2D9D1; border-radius: 12px; background: #fff; }
.field input:focus, .field select:focus { border-color: var(--brand); outline: 3px solid rgba(242, 107, 29, .18); }
.code-input { text-align: center; letter-spacing: .5em; font-size: 24px; font-weight: 700; padding-left: calc(14px + .5em) !important; }
.form-msg { margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.form-msg.err { background: var(--err-bg); color: var(--err); }
.form-msg.info { background: var(--brand-soft); color: var(--brand-2); }
.badge.soon { font-size: 11.5px; font-weight: 700; color: var(--warn); background: var(--warn-bg); padding: 3px 9px; border-radius: 999px; white-space: nowrap; }

/* ---------- auth screens ---------- */
body:not([data-view="app"]) { background: linear-gradient(180deg, #FFF1E6 0%, var(--bg) 46%); }
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 18px; }
.auth-card { width: min(100%, 420px); background: #fff; border: 1px solid var(--line); border-radius: 22px; padding: 32px 28px; box-shadow: 0 18px 50px rgba(120, 50, 10, .1); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand span { font-size: 26px; font-weight: 800; color: var(--brand); letter-spacing: -.01em; }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.auth-foot { color: var(--ink-3); font-size: 13px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; width: var(--side-w); flex: none; display: flex; flex-direction: column; padding: 22px 14px 16px; overflow-y: auto; color: #fff; background: linear-gradient(180deg, #F5731F 0%, #E9590D 100%); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; color: #fff; text-decoration: none; }
.brand-name { font-size: 24px; font-weight: 800; letter-spacing: -.01em; }
.nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 0; background: none; color: rgba(255, 255, 255, .95); text-decoration: none; text-align: left; font-weight: 600; font-size: 15px; cursor: pointer; }
.nav-item:hover { background: rgba(255, 255, 255, .16); }
.nav-item.active { background: #fff; color: var(--brand); box-shadow: 0 4px 12px rgba(120, 40, 0, .18); }
.side-foot { margin-top: auto; padding-top: 14px; display: grid; gap: 2px; border-top: 1px solid rgba(255, 255, 255, .24); }
.nav-item.soft { font-weight: 500; font-size: 14px; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px; height: 66px; padding: 0 28px; background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.m-brand { display: none; }
.search { flex: 1; max-width: 440px; display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; color: var(--ink-3); }
.search input { flex: 1; min-width: 0; padding: 0; border: 0; background: none; outline: 0; }
.search input:disabled { cursor: not-allowed; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-btn { position: relative; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); cursor: pointer; }
.tenant-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; padding: 6px 11px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--ink-2); font-size: 12.5px; }
.tenant-chip.t-mobile { display: none; }
.tenant-chip .ic { width: 15px; height: 15px; }
.tenant-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account { display: flex; align-items: center; gap: 10px; padding: 5px 10px 5px 5px; background: #fff; border: 1px solid var(--line); border-radius: 14px; cursor: pointer; text-align: left; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 700; flex: none; }
.who { display: grid; line-height: 1.25; max-width: 150px; }
.who b { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: var(--ink-3); font-size: 11.5px; }
.caret { width: 16px; height: 16px; color: var(--ink-3); }
.pop-wrap { position: relative; }
.pop { position: absolute; right: 0; top: calc(100% + 8px); width: 260px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 32px rgba(60, 30, 10, .16); z-index: 60; }
.pop[hidden] { display: none; }
.pop b { font-size: 14px; }
.pop .muted { margin-top: 4px; font-size: 13px; }
.pop-user { display: grid; gap: 1px; padding-bottom: 10px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.pop-user small { color: var(--ink-3); font-size: 12.5px; overflow-wrap: anywhere; }
.pop-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 8px; border: 0; border-radius: 10px; background: none; color: var(--ink); text-decoration: none; font-size: 14px; cursor: pointer; text-align: left; }
.pop-item:hover { background: var(--bg); }

.view { width: 100%; max-width: 1360px; margin: 0 auto; padding: 28px 32px 56px; outline: 0; }

/* ---------- page parts ---------- */
.greet, .page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.greet h1, .page-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
.sub { margin-top: 4px; color: var(--ink-2); font-size: 14.5px; }
.date-chip { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; background: #fff; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-2); font-size: 13.5px; white-space: nowrap; }
.date-chip .ic { width: 17px; height: 17px; color: var(--brand); }
.page-actions { display: flex; align-items: center; gap: 10px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { display: flex; align-items: center; gap: 14px; min-width: 0; padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi-ic { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.kpi-ic.k-orange { background: var(--brand-soft); color: var(--brand); }
.kpi-ic.k-blue { background: var(--blue-bg); color: var(--blue); }
.kpi-ic.k-amber { background: var(--amber-bg); color: var(--amber); }
.kpi-body { display: grid; min-width: 0; }
.kpi-label { font-size: 13px; color: var(--ink-2); }
.kpi-val { font-size: 30px; font-weight: 800; line-height: 1.15; }
.kpi-val small { margin-left: 3px; font-size: 15px; font-weight: 700; }
.kpi-note { font-size: 11.5px; color: var(--ink-3); }

.card { min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 16px; font-weight: 800; }
.count { padding: 2px 9px; border-radius: 999px; background: var(--bg); color: var(--ink-3); font-size: 12.5px; }
.grow { flex: 1; }
.more { display: inline-flex; align-items: center; gap: 2px; color: var(--brand); font-weight: 600; font-size: 13.5px; text-decoration: none; }
.more .ic { width: 16px; height: 16px; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.table { display: block; }
.row { display: grid; align-items: center; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--line); }
.row.head { border-top: 0; padding-top: 10px; padding-bottom: 10px; background: #FCFAF8; color: var(--ink-3); font-size: 12.5px; font-weight: 600; }
.agents-table .row { grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
.calls-table .row, .ivr-table .row { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.cell { min-width: 0; }
.c-name { display: flex; align-items: center; gap: 12px; }
.row.head .c-name { display: block; }
.avatar-sm { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.name-wrap { display: grid; min-width: 0; }
.name-wrap b { overflow-wrap: anywhere; }
.name-wrap small { color: var(--ink-3); font-size: 12.5px; }
.c-upd { color: var(--ink-3); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.off { background: var(--off-bg); color: var(--off); }
.pill.err { background: var(--err-bg); color: var(--err); }

.empty { display: grid; justify-items: center; gap: 6px; padding: 40px 20px; text-align: center; }
.empty-ic { width: 56px; height: 56px; margin-bottom: 6px; display: grid; place-items: center; border-radius: 50%; background: var(--brand-soft); color: var(--brand); }
.empty-ic .ic { width: 26px; height: 26px; }
.empty b { font-size: 15px; }
.empty p { max-width: 360px; color: var(--ink-2); font-size: 13.5px; }
.empty .btn { margin-top: 10px; }
.skeleton { display: grid; gap: 12px; padding: 16px 20px; }
.skeleton i { height: 44px; border-radius: 10px; background: linear-gradient(90deg, #F3EEE9 25%, #FAF7F4 50%, #F3EEE9 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

.set-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.set-card { padding: 20px; display: grid; gap: 4px; align-content: start; }
.set-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.set-head h2 { flex: 1; font-size: 16px; font-weight: 800; }
.set-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kv span { color: var(--ink-2); flex: none; }
.kv b { text-align: right; overflow-wrap: anywhere; }
.set-card .btn { justify-self: start; margin-top: 10px; }
.set-form { display: grid; gap: 2px; }
.set-form .field { margin: 4px 0 10px; }
.set-form .kv:last-of-type { border-bottom: 0; }
.ro-note { margin-top: 6px; font-size: 12.5px; color: var(--ink-3); }
.field input:disabled { background: var(--bg); color: var(--ink-2); cursor: not-allowed; }
.field input:read-only:not(:disabled) { background: #FBF8F5; }
.form-msg.ok { background: var(--ok-bg); color: var(--ok); }
.btn .spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff; animation: spin .7s linear infinite; }
.btn .spin[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.more-menu { margin-top: 16px; }
.more-menu h2 { padding: 16px 16px 6px; font-size: 16px; }
.menu-link { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.menu-link .ic { color: var(--brand); }
.menu-link .chev { margin-left: auto; color: var(--ink-3); }

dialog { width: min(calc(100vw - 32px), 440px); padding: 24px; border: 0; border-radius: 20px; background: #fff; color: var(--ink); box-shadow: 0 24px 60px rgba(40, 20, 5, .3); }
dialog::backdrop { background: rgba(30, 20, 10, .45); }
dialog h2 { font-size: 18px; margin-bottom: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 80; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px; background: #2B2622; color: #fff; font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.toast[hidden] { display: none; }
.toast.err { background: var(--err); }
.tabbar { display: none; }

/* ---------- 1024-1279: two-column KPIs, stacked home grid ---------- */
@media (max-width: 1279px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1199px) { .home-grid { grid-template-columns: 1fr; } }

/* ---------- 769-1023: compact (icon) sidebar ---------- */
@media (max-width: 1023px) and (min-width: 769px) {
  :root { --side-w: 76px; }
  .sidebar { padding: 22px 10px 16px; }
  .brand { justify-content: center; padding: 0 0 22px; }
  .brand-name, .nav-label, .who, .caret { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .view { padding: 24px 24px 48px; }
  .topbar { padding: 0 20px; }
  .account { padding: 4px; }
  .set-grid { grid-template-columns: 1fr; }
}

/* ---------- mobile (<= 768px): header + sheet + bottom navigation ---------- */
@media (max-width: 768px) {
  .sidebar, .search, .tenant-chip.t-desktop, .who, .caret, .date-chip { display: none; }
  .shell { display: block; }
  .topbar { position: relative; z-index: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "brand actions" "tenant tenant"; gap: 10px 8px; height: auto; padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 40px; background: linear-gradient(135deg, #F5731F, #E9590D); border: 0; color: #fff; backdrop-filter: none; }
  .m-brand { grid-area: brand; display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 22px; font-weight: 800; }
  .top-actions { grid-area: actions; margin: 0; gap: 8px; }
  .icon-btn { width: 40px; height: 40px; background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .32); color: #fff; }
  .tenant-chip.t-mobile { grid-area: tenant; display: inline-flex; justify-self: start; max-width: 100%; background: rgba(255, 255, 255, .2); border-color: rgba(255, 255, 255, .38); color: #fff; }
  .account { padding: 0; border: 0; background: none; }
  .avatar { width: 40px; height: 40px; background: #fff; color: var(--brand); }
  .pop-wrap { position: static; }
  .pop { right: 12px; top: 64px; width: min(290px, calc(100vw - 24px)); color: var(--ink); }
  .view { position: relative; z-index: 1; margin-top: -24px; padding: 22px 16px calc(var(--tab-h) + 32px + env(safe-area-inset-bottom, 0px)); min-height: calc(100vh - 110px); background: #fff; border-radius: 24px 24px 0 0; }
  .greet h1, .page-head h1 { font-size: 22px; }
  .sub { font-size: 13.5px; }
  .greet, .page-head { margin-bottom: 16px; }
  .page-head { flex-wrap: wrap; }
  .kpis { gap: 12px; margin-bottom: 16px; }
  .kpi { gap: 10px; padding: 12px; }
  .kpi-ic { width: 40px; height: 40px; }
  .kpi-ic .ic { width: 19px; height: 19px; }
  .kpi-val { font-size: 24px; }
  .kpi-label { font-size: 12px; }
  .home-grid, .set-grid { grid-template-columns: 1fr; gap: 14px; }
  .card-head { padding: 12px 14px; gap: 8px 10px; }
  .card-head .count { display: none; }
  .only-m { display: block; }
  .t-long { display: none; }
  .t-short { display: inline; }
  .row { padding: 12px 14px; }
  .agents-table .row { grid-template-columns: minmax(0, 1fr) auto; }
  .agents-table .row.head, .calls-table .row.head, .ivr-table .row.head { display: none; }
  .c-type, .c-upd { display: none; }
  .empty { padding: 32px 16px; }
  .toast { bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom, 0px)); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(60, 30, 10, .06); }
  .tab { flex: 1; min-width: 0; display: grid; justify-items: center; align-content: center; gap: 3px; color: var(--ink-3); text-decoration: none; font-size: clamp(9px, 2.7vw, 11px); font-weight: 600; white-space: nowrap; }
  .tab .ic { width: 23px; height: 23px; }
  .tab.active { color: var(--brand); }
  .auth-card { padding: 28px 22px; }
  .set-form .btn { justify-self: stretch; width: 100%; }
  .set-card { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
