/* Calculator (design 1, Grid): every calculator tiled in two rows with the history on the right; on a phone one
   calculator at a time, a strip of tabs, and the history in a sheet. Tokens, fonts, .btn and .ycp come from
   /css/txlist.css (the dashboard's current look). */
body { background-color: #11141A; }


.cx { --tab: #9B7BFF; --err: #FF8A8A; --op: #C3B5FF; --key: #1B2030; --key-2: #222839;
  display: flex; flex-direction: column; gap: 16px; height: calc(100vh - 100px); min-height: 640px; padding: 22px 28px 24px; }
.cx-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex: none; }
.cx-head h1 { margin: 0; font-family: "titles", sans-serif !important; font-weight: 400; font-size: 30px; color: #E4E8EF; line-height: 1.1; }
.cx-sub { display: flex; align-items: center; gap: 6px; margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.cx-sub .i { color: var(--in); }
.cx-actions { display: flex; align-items: center; gap: 10px; }
.cx-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.cx-count b { color: var(--text); font-weight: 600; }
.cx-full { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 10px; font-size: 12.5px; color: var(--hold);
  background: rgba(245, 185, 74, .08); border: 1px solid rgba(245, 185, 74, .25); }
.cx-hbtn { display: none !important; }

.cx-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
.cx-grid { min-height: 0; display: grid; gap: 12px; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); grid-template-rows: repeat(var(--rows, 2), minmax(0, 1fr)); }

/* one calculator */
.cx-tile { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; border-radius: 18px; background: var(--surface);
  border: 1px solid var(--line); overflow: hidden; }
.cx-tile.focus { border: 1.5px solid transparent; background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--grad) border-box;
  box-shadow: 0 10px 30px rgba(94, 123, 255, .14); }
.cx-tile-head { flex: none; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px 0 14px; border-bottom: 1px solid var(--line); }
.cx-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--tab); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tab) 20%, transparent); }
.cx-name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-name-input { flex: 1; min-width: 0; height: 28px; padding: 0 8px; margin-left: -8px; border-radius: 7px; border: 1px solid #6B6BFF; background: var(--bg);
  color: var(--text); font-size: 13.5px; font-weight: 500; outline: 0; }
.cx-name-count { font-size: 11px; color: var(--muted-2); }
.ycp .cx-ic { flex: none; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 8px; background: none; color: var(--muted); padding: 0; }
.ycp .cx-ic:hover { background: var(--surface-2); color: var(--text); }

.cx-display { flex: none; position: relative; display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; gap: 2px;
  padding: 10px 14px 10px; min-height: 84px; }
.cx-expr { max-width: 100%; min-height: 18px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: right; }
.cx-expr bdi { direction: ltr; unicode-bidi: isolate; }
.cx-value { --vs: 30px; max-width: calc(100% - 34px); font-size: var(--vs); font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  direction: rtl; text-align: right; letter-spacing: -.01em; line-height: 1.2; }
.cx-value[data-len="m"] { font-size: calc(var(--vs) * .84); }
.cx-value[data-len="l"] { font-size: calc(var(--vs) * .7); }
.cx-value[data-len="xl"] { font-size: calc(var(--vs) * .58); }
.cx-value bdi { direction: ltr; unicode-bidi: isolate; }
.cx-value .caret { display: inline-block; width: 2px; height: .95em; margin-left: 2px; vertical-align: -.1em; background: #9B7BFF; }
.cx-preview { color: var(--muted); }
.cx-error { display: flex; align-items: center; gap: 6px; max-width: 100%; font-size: 12px; color: var(--err); text-align: right; }
.cx-tile.has-error .cx-value { color: var(--err); }
.ycp .cx-back { position: absolute; left: 8px; bottom: 12px; width: 34px; height: 30px; display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px; background: none; color: var(--muted); }
.ycp .cx-back:hover { background: var(--surface-2); color: var(--text); }

.cx-keys { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 6px; padding: 0 10px 10px; }
.ycp .cx-key { min-height: 0; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 11px; background: var(--key);
  color: var(--text); font-size: 17px; font-weight: 500; padding: 0; transition: background .1s; }
.ycp .cx-key:hover { background: var(--key-2); }
.ycp .cx-key.op { color: var(--op); background: rgba(155, 123, 255, .10); font-size: 19px; }
.ycp .cx-key.op:hover { background: rgba(155, 123, 255, .18); }
.ycp .cx-key.fn { color: var(--text-2); background: #191E2B; font-size: 15px; }
.ycp .cx-key.clear { color: #FF9C9C; }
.ycp .cx-key.eq { background: var(--grad); color: #fff; font-size: 21px; box-shadow: 0 6px 16px rgba(94, 123, 255, .28); }

/* the empty slot that opens a new calculator */
.ycp .cx-new { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; border-radius: 18px; border: 1.5px dashed #2E3550;
  background: transparent; color: var(--muted); font-size: 14px; font-weight: 500; }
.ycp .cx-new i { width: 44px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center; color: #C3B5FF;
  background: rgba(155, 123, 255, .12); }
.ycp .cx-new:hover { border-color: #4A4F78; color: var(--text); }

/* history */
.cx-history { min-height: 0; display: flex; flex-direction: column; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.cx-history-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 14px 10px 16px; }
.cx-history-head h2 { margin: 0; font-family: 'YCP UI', Arial, sans-serif !important; font-size: 15px; font-weight: 600; color: var(--text); }
.ycp .cx-clear { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line-2);
  background: none; color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.ycp .cx-clear:hover { border-color: rgba(255, 138, 138, .5); color: #FFB0B0; }
.cx-seg { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 0 14px 6px; padding: 3px; border-radius: 10px; background: var(--bg); }
.ycp .cx-seg button { height: 28px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.ycp .cx-seg button.on { background: var(--surface-3); color: var(--text); }
.cx-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 8px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.cx-day { margin: 10px 8px 6px; font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted-2); }
.ycp .cx-entry { width: 100%; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; padding: 9px 10px; border: 0; border-radius: 11px; background: none; text-align: right; }
.ycp .cx-entry:hover { background: var(--surface-2); }
.cx-entry-top { width: 100%; display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.cx-entry-top .cx-dot { width: 6px; height: 6px; box-shadow: none; }
.cx-entry-top span { flex: 1; min-width: 0; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-entry-expr { max-width: 100%; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.cx-entry-res { max-width: 100%; font-size: 16px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.cx-history-foot { flex: none; padding: 10px 16px 12px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted-2); }
.cx-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 46px 18px; text-align: center; color: var(--muted); font-size: 13px; }
.cx-empty i { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--muted); }
.cx-toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 10px; padding: 11px 16px;
  border-radius: 12px; background: #232A3B; border: 1px solid var(--line-2); color: var(--text); font-size: 13px; box-shadow: 0 14px 34px rgba(0,0,0,.45); }
.cx-toast .i { color: var(--in); }

/* the phone's strip of tabs */
.ycp .cx-tab { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text-2); font-size: 13.5px; font-weight: 500; max-width: 230px; }
.ycp .cx-tab .cx-name { flex: 0 1 auto; color: inherit; }
.ycp .cx-tab.on { color: #fff; border: 1.5px solid transparent; background: linear-gradient(var(--surface-2), var(--surface-2)) padding-box, var(--grad) border-box; }
.ycp .cx-tab-add { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 38px; border-radius: 12px; border: 1.5px dashed #2E3550;
  background: none; color: var(--muted); }

/* what only the real page has: loading, switched off, could not load, a save waiting, a name refused */
.cx-loading { margin: 0; font-size: 14px; color: var(--muted); }
.cx-notice { align-self: flex-start; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; max-width: 520px; padding: 24px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line); }
.cx-notice > i { width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center; color: #C3B5FF; background: rgba(155, 123, 255, .12); }
.cx-notice.failed > i { color: var(--err); background: rgba(255, 138, 138, .1); }
.cx-notice h2 { margin: 4px 0 0; font-family: 'YCP UI', Arial, sans-serif !important; font-size: 17px; font-weight: 600; color: var(--text); }
.cx-notice p { margin: 0 0 6px; font-size: 14px; line-height: 1.5; color: var(--text-2); }
.cx-unsaved { flex: none; display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 500;
  color: var(--hold); background: rgba(245, 185, 74, .1); white-space: nowrap; }
.cx-tile-head.has-error { flex-wrap: wrap; height: auto; min-height: 40px; padding-top: 6px; padding-bottom: 6px; }
.cx-name-error { flex-basis: 100%; font-size: 12px; color: var(--err); }
.cx-tile.busy .cx-value { opacity: .6; }
.ycp .cx-key[disabled], .ycp .cx-new[disabled], .ycp .cx-tab-add[disabled] { opacity: .5; cursor: default; }
.ycp .cx-seg button[disabled] { opacity: .5; cursor: default; }
.ycp .cx-seg button span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; }
.cx-entry-res.long { font-size: 14px; }
.ycp .cx-new.first { max-width: 520px; max-height: 360px; justify-self: start; width: 100%; }

/* ---- phones: one calculator at a time, tabs as a scrolling strip, history in a sheet ---- */
@media (max-width: 750px) {
  .cx { height: auto; min-height: 0; padding: 14px 14px 0; gap: 12px; }
  .cx-head h1 { font-size: 24px; }
  .cx-sub { display: none; }
  .cx-count { display: none; }
  .cx-head .btn.primary { display: none; }
  .cx-hbtn { display: inline-flex !important; }
  .cx-body { display: block; }
  .cx-history { display: none; }
  .cx-grid { display: block; }
  .cx-grid > :not(.focus) { display: none; }
  .cx-grid > .cx-new.first { display: flex; min-height: 220px; }
  .cx-ptabs { display: flex; flex-wrap: nowrap; gap: 8px; max-height: none; overflow-x: auto; margin: 0 -14px; padding: 0 14px 2px; scrollbar-width: none; }
  .cx-ptabs::-webkit-scrollbar { display: none; }
  .ycp .cx-tab { flex: none; height: 38px; max-width: 180px; }
  .ycp .cx-tab small { display: none; }
  .cx-tile { border-radius: 22px; }
  .cx-tile-head { height: 44px; padding-left: 16px; }
  .cx-display { min-height: 132px; padding: 12px 18px 12px; }
  .cx-expr { font-size: 15px; }
  .cx-value { --vs: 44px; }
  .cx-keys { grid-template-rows: repeat(5, 58px); gap: 9px; padding: 0 14px 14px; }
  .ycp .cx-key { font-size: 22px; border-radius: 16px; }
  .ycp .cx-back { bottom: 16px; left: 12px; }
}
@media (min-width: 751px) {
  .cx-ptabs { display: none; }
}

/* the bottom sheet for history on phones */
.cx-sheet { position: fixed; inset: 0; z-index: 1100; display: flex; flex-direction: column; justify-content: flex-end; background: rgba(5, 6, 10, .62); }
.cx-sheet .cx-history { display: flex; max-height: 78vh; border-radius: 24px 24px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
.cx-grab { width: 40px; height: 4px; margin: 10px auto 0; border-radius: 2px; background: #3A4257; }

