:root {
  --bg: #0e1116;
  --card: #171b22;
  --line: #2a3140;
  --text: #e8ecf3;
  --muted: #93a0b4;
  --accent: #22d3ee;
  --ok: #34d399;
  --bad: #f87171;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 10% -10%, #163047 0%, transparent 55%),
    radial-gradient(700px 400px at 90% 0%, #2a1840 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0; }
.err { color: var(--bad); min-height: 1.2em; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card, .card, .modal-card {
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(8px);
}
.login-card {
  width: min(380px, 100%);
  padding: 28px;
  display: grid;
  gap: 12px;
}
.login-card h1, .top h1 { margin: 0 0 4px; letter-spacing: -0.02em; }
.guest-login-btn { width: 100%; margin-top: 4px; }
.guest-login-hint { font-size: 12px; text-align: center; margin: 0; }
.read-only-badge {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #fbbf24;
  border: 1px solid color-mix(in srgb, #fbbf24 45%, var(--line));
  background: color-mix(in srgb, #fbbf24 12%, transparent);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
body.read-only-mode .tag-form,
body.read-only-mode #dealSave,
body.read-only-mode #entrySaveDesc,
body.read-only-mode #diaryAddEntry,
body.read-only-mode .upload-btn,
body.read-only-mode .paste-hint,
body.read-only-mode .td-menu,
body.read-only-mode .td-menu-slot,
body.read-only-mode .row-menu-btn {
  display: none !important;
}
body.read-only-mode .reason-dd-btn {
  pointer-events: none;
  opacity: 0.55;
}
body.read-only-mode .pill button {
  display: none;
}
body.read-only-mode #dealNote,
body.read-only-mode #entryDescription,
body.read-only-mode .diary-row select,
body.read-only-mode .diary-row input[type="date"],
body.read-only-mode .basis-btn,
body.read-only-mode .r-calc-row input,
body.read-only-mode #rCalcSave {
  pointer-events: none;
  opacity: 0.85;
}
body.read-only-mode #dealTagPick input {
  pointer-events: none;
}
body.read-only-mode .rating-row .star {
  pointer-events: none;
}
body.read-only-mode .img-del {
  display: none;
}
body.read-only-mode #changePasswordBtn {
  display: none;
}

.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 4px; }
.auth-tab {
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--muted);
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
}
.auth-tab.active {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}
.auth-panel { display: grid; gap: 12px; }
.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.ok { color: #34d399; font-size: 13px; margin: 0; min-height: 1.2em; white-space: pre-line; }
.reg-password-box {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, #34d399 40%, var(--line));
  background: color-mix(in srgb, #34d399 10%, #0c1017);
  font-family: ui-monospace, monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
  color: #ecfdf5;
}

.user-menu-wrap { position: relative; }
.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--line));
  background: color-mix(in srgb, var(--accent) 18%, #0c1017);
  color: #e2e8f0;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 180px;
  background: #121924;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  z-index: 50;
}
.user-menu button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.user-menu button:hover { background: #1a2330; }

.install-card {
  padding: 24px 28px 32px;
  max-width: 960px;
}
.install-card > .muted {
  margin: 0 0 22px;
  line-height: 1.6;
  font-size: 14px;
}
.install-download { margin: 0 0 26px; }
.download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: 12px;
  background: var(--accent);
  color: #041016 !important;
  text-decoration: none !important;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  transition: filter 0.15s ease;
}
.download-btn:hover { filter: brightness(1.08); }
.install-token {
  margin: 0 0 30px;
  padding: 18px 20px !important;
}
.install-token h3 { margin: 0 0 8px; font-size: 15px; }
.install-token .muted { margin: 0 0 4px; }
.install-token .ghost { margin-top: 12px; }
.token-code {
  display: block;
  padding: 14px 16px;
  border-radius: 10px;
  background: #0c1017;
  border: 1px solid var(--line);
  word-break: break-all;
  margin: 12px 0 0;
  font-size: 13px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  line-height: 1.5;
  color: #e2e8f0;
}
.install-steps {
  margin: 0 0 8px;
  padding-left: 1.35rem;
  display: grid;
  gap: 20px;
  line-height: 1.65;
  font-size: 14px;
}
.install-steps > li { padding-left: 6px; }
.install-steps > li::marker { color: var(--accent); font-weight: 700; }
.install-steps ul {
  margin: 12px 0 0;
  padding-left: 1.25rem;
  display: grid;
  gap: 10px;
  list-style: disc;
}
.install-steps code {
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 6px;
  background: #0c1017;
  border: 1px solid var(--line);
  font-family: ui-monospace, monospace;
}
.install-note {
  margin-top: 28px;
  padding: 18px 20px !important;
}
.install-note h3 { margin: 0 0 12px; font-size: 15px; }
.install-note p { margin: 0 0 12px; line-height: 1.6; font-size: 14px; }
.install-note ul {
  margin: 0;
  padding-left: 1.25rem;
  display: grid;
  gap: 12px;
  line-height: 1.6;
  font-size: 14px;
}

input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--text);
  font-size: 15px;
}

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--text);
  font-size: 15px;
}
input[type="color"] {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0c1017;
  padding: 7px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}
input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  background: var(--accent);
  color: #04212a;
  font-weight: 700;
  cursor: pointer;
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 600;
}
button:hover { filter: brightness(1.08); }

#app { max-width: 1480px; margin: 0 auto; padding: 0 18px 48px; }
.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 18px 48px;
}
.site-header {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 18px 0;
}
.site-header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.site-brand { flex: 1; min-width: 180px; }
.site-brand h1 { margin: 0 0 4px; letter-spacing: -0.02em; font-size: 22px; }
.site-brand .muted { font-size: 13px; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.pnl-card {
  margin-bottom: 16px;
}
.pnl-meta {
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}
.pnl-chart {
  height: 280px;
  width: 100%;
  margin-top: 8px;
}
.empty-chart {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

.grid-2 {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
}
.card { padding: 16px; }
.card-deals { overflow: hidden; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; font-size: 16px; }

.tag-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.tag-form input[type="text"] {
  height: 42px;
  padding-top: 0;
  padding-bottom: 0;
}
.tag-form > button[type="submit"] {
  height: 42px;
  padding-top: 0;
  padding-bottom: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-sizing: border-box;
}
.tags-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 6px 10px 6px 12px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
  background: color-mix(in srgb, currentColor 18%, transparent);
  white-space: nowrap;
}
.pill button {
  padding: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: color-mix(in srgb, #000 35%, transparent);
  color: #fff;
  font-size: 12px;
  line-height: 1;
}

.tag-stats { display: grid; gap: 8px; }
.tag-filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12px;
}
.tag-filter-bar .filter-clear {
  padding: 4px 10px;
  font-size: 12px;
}
.pnl-filter-pill {
  font-size: 12px;
  padding: 4px 8px;
}
.tag-stat {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #10151d;
  font-size: 13px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}
.tag-stat.filter-row:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: #121924;
}
.tag-stat.filter-row.active {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}
.filter-all-label {
  font-weight: 700;
  color: #e2e8f0;
}
.tag-stat .meta { color: var(--muted); grid-column: 1 / -1; }

.deals-wrap {
  overflow: auto;
  max-height: 72vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0c1017;
}
.deals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 980px;
}
.deals-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  background: #121821;
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  white-space: nowrap;
}
.deals-table tbody td {
  padding: 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  vertical-align: middle;
}
.deal-row {
  cursor: pointer;
  transition: background .12s ease;
}
.deal-row:hover { background: #141a24; }
.td-entry { color: var(--text); white-space: nowrap; }
.td-symbol { font-weight: 600; white-space: nowrap; }
.td-reason { min-width: 140px; }
.reason-picker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
}
.reason-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}
.reason-empty { color: var(--muted); }
.reason-dd-btn {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.reason-dd-btn:hover,
.reason-dd-btn.open {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent, #22d3ee) 50%, var(--line));
  background: #161d28;
}
.reason-dd-btn.open svg { transform: rotate(180deg); }
.reason-dd-btn svg { transition: transform .15s ease; display: block; }
.reason-menu {
  position: fixed;
  z-index: 1000;
  min-width: 180px;
  max-width: 280px;
  max-height: min(320px, 60vh);
  overflow: auto;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #121821;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.reason-menu-empty {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}
.reason-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.reason-menu-item:hover { background: #1a2330; }
.reason-menu-item.on { background: color-mix(in srgb, #22d3ee 10%, transparent); }
.reason-check {
  width: 14px;
  flex: 0 0 14px;
  font-size: 12px;
  color: #22d3ee;
  text-align: center;
}
.reason-menu-pill {
  pointer-events: none;
  padding: 4px 10px;
  font-size: 12px;
}
.td-dur { color: var(--muted); white-space: nowrap; }
.td-side { font-weight: 600; }
.td-vol { white-space: nowrap; color: var(--text); }
.td-pnl { font-weight: 700; white-space: nowrap; text-align: right; }
.exec-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  margin-right: 6px;
  font-size: 14px;
  font-weight: 800;
  vertical-align: middle;
}
.exec-mark-empty { visibility: hidden; }
.exec-mark-ok { color: #34d399; }
.exec-mark-err { color: #f87171; }
.th-menu, .td-menu {
  width: 40px;
  padding-left: 4px !important;
  padding-right: 8px !important;
  text-align: center;
}
.row-menu-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.row-menu-btn:hover,
.row-menu-btn.open {
  background: #161d28;
  color: var(--text);
}
.burger-line {
  display: block;
  width: 14px;
  height: 1.5px;
  border-radius: 1px;
  background: currentColor;
}
.row-menu {
  position: fixed;
  z-index: 1000;
  min-width: 160px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #121821;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.row-menu-item {
  width: 100%;
  display: block;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.row-menu-item:hover { background: #1a2330; }
.td-pct { white-space: nowrap; }
.pct-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 12px;
  border: 1px solid transparent;
}
.pct-pill.pos {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  border-color: color-mix(in srgb, var(--ok) 35%, transparent);
}
.pct-pill.neg {
  color: var(--bad);
  background: color-mix(in srgb, var(--bad) 16%, transparent);
  border-color: color-mix(in srgb, var(--bad) 35%, transparent);
}

.modal-tags {
  display: grid;
  gap: 8px;
  margin: 0;
}
.modal-tags label {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  background: #0c1017;
}

/* Deal detail view */
.deal-view {
  position: fixed;
  inset: 0;
  z-index: 40;
  background:
    radial-gradient(900px 500px at 10% -10%, #163047 0%, transparent 55%),
    radial-gradient(700px 400px at 90% 0%, #2a1840 0%, transparent 50%),
    var(--bg);
  overflow: auto;
}
.deal-view-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 18px 48px;
  display: grid;
  gap: 14px;
}
.deal-view-top {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.deal-view-title { flex: 1; min-width: 200px; }
.deal-view-title h2 { margin: 0 0 2px; font-size: 22px; }
.deal-chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.tf-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #121821;
}
.tf-btn {
  padding: 7px 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 13px;
}
.tf-btn.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}
.tv-chart {
  width: 100%;
  height: min(62vh, 560px);
  background: #0b0e13;
  position: relative;
}
.chart-loading {
  padding: 24px 16px;
  margin: 0;
}
.chart-hint { padding: 8px 14px 12px; font-size: 12px; margin: 0; }

.deal-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.card.soft {
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}
.card.soft h3 {
  margin: 0 0 12px;
  font-size: 15px;
}
.ratings { display: grid; gap: 12px; }
.rating-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.exec-quality {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.exec-opt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.exec-opt:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.exec-opt input { accent-color: var(--accent); }

.section-gap { margin-top: 18px; }

.entry-bases { display: flex; flex-direction: column; gap: 10px; }
.basis-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.15fr) auto;
  gap: 8px;
  align-items: end;
}
.basis-field {
  min-width: 0;
}
.basis-row select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--text);
  font-size: 13px;
}
.basis-row-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  white-space: nowrap;
}
.basis-row > .ghost,
.basis-row > span:last-child {
  align-self: center;
  margin-bottom: 6px;
}

.rating-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.stars { display: inline-flex; gap: 4px; }
.star {
  width: 28px;
  height: 28px;
  border: 0;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  color: #3a4558;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.star.on { color: #fbbf24; text-shadow: 0 0 10px rgba(251, 191, 36, .35); }
.star:hover { filter: brightness(1.15); }

.note-card textarea {
  width: 100%;
  resize: vertical;
  min-height: 140px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}
.save-status { margin: 8px 0 0; min-height: 1.2em; font-size: 13px; }

@media (max-width: 900px) {
  .grid-2, .stats, .deal-meta-grid { grid-template-columns: 1fr; }
  .tag-form { grid-template-columns: 1fr auto; }
  .tag-form button { grid-column: 1 / -1; }
  .tv-chart { height: 420px; }
  .diary-weeks-grid { grid-template-columns: 1fr; }
  .diary-sheet { min-width: 860px; }
}

/* Main nav */
.main-nav {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.nav-tab {
  padding: 10px 18px;
  border-radius: 999px;
  background: #121821;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}
.nav-tab:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--accent);
}
.nav-tab.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* Diary shell */
.diary-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.diary-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.diary-filters select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--text);
  font: inherit;
}
.diary-month-title {
  margin: 0 0 14px;
  font-size: 28px;
  letter-spacing: -0.02em;
}
.diary-weeks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.week-card {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 12px;
  transition: border-color .15s, transform .15s;
}
.week-card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  transform: translateY(-1px);
}
.week-card.upcoming {
  border-style: dashed;
  opacity: .92;
}
.week-period {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
  text-transform: uppercase;
}
.week-metrics {
  display: grid;
  gap: 8px;
}
.wm {
  background: #0c1017;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.wm-v {
  display: block;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}
.wm-k {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

/* Diary week sheet — one compact row per trade */
.diary-table-wrap {
  overflow-x: auto;
  padding: 0;
}
.diary-sheet {
  width: 100%;
}
.diary-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  width: 100%;
}
.diary-row:last-child { border-bottom: 0; }
.diary-row-head {
  background: #121821;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.diary-row-head .d-col {
  padding: 10px 8px 8px;
  align-items: flex-start;
}
.d-col {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 8px 6px;
  border-right: 1px solid var(--line);
  min-height: 52px;
  box-sizing: border-box;
  min-width: 0;
}
.d-col:last-child { border-right: 0; }
.d-date { flex: 0 0 148px; max-width: 148px; }
.d-side { flex: 0 0 100px; max-width: 100px; }
.d-bases { flex: 1 1 340px; min-width: 300px; }
.d-form { flex: 0 0 132px; max-width: 132px; }
.d-result { flex: 0 0 108px; max-width: 108px; }
.d-r { flex: 0 0 88px; max-width: 88px; }
.d-sys { flex: 0 0 88px; max-width: 88px; }
.d-skip { flex: 0 0 88px; max-width: 88px; }
.d-act {
  flex: 0 0 36px;
  width: 36px;
  max-width: 36px;
  justify-content: center;
  padding: 8px 2px;
}

.cell-inp, .cell-sel {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.cell-date {
  padding-right: 4px;
}
.cell-sel {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) calc(50% - 2px), calc(100% - 9px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 22px;
}
.bases-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
}
.basis-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1px;
  width: 100%;
  min-width: 0;
  height: 22px;
  padding: 0 2px;
  border-radius: 6px;
  background: #0c1017;
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
}
.bf-tf {
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.bf-val {
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.basis-menu {
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  min-width: 160px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.basis-opt {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.basis-opt:hover { background: #1a2330; }
.r-open-btn {
  width: 100%;
  min-width: 0;
  padding: 7px 6px;
  border-radius: 8px;
  background: #0c1017;
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.row-dots {
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}
.row-skip { opacity: .55; }
.diary-menu {
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  min-width: 140px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.diary-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  border: 0;
  padding: 10px 14px;
  font-weight: 600;
}
.diary-menu button:hover { background: #1a2330; }
.diary-menu button.danger { color: var(--bad); }

/* Entry detail images */
.entry-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.img-thumb {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 4/3;
  background: #0c1017;
}
.img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
}
.img-thumb .img-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.65);
  color: #fff;
  border: 0;
  font-size: 16px;
  line-height: 1;
}
.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.upload-btn:hover { border-color: var(--accent); color: var(--accent); }
.entry-images-card {
  outline: none;
}
.entry-images-card:focus-visible {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}
.paste-hint {
  margin: -4px 0 10px;
  font-size: 12px;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, .62);
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal-card {
  width: min(520px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  padding: 20px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-x {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}
.modal-actions { margin-top: 14px; }
.r-calc-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.r-calc-row input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--text);
  font: inherit;
}
.r-sep { color: var(--muted); font-weight: 700; }
.r-calc-total {
  margin-top: 12px;
  font-size: 18px;
  font-weight: 700;
}
.compare-card select[multiple] {
  width: 100%;
  margin: 10px 0;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0c1017;
  color: var(--text);
  font: inherit;
}
.compare-result { margin-top: 16px; }
.compare-block { margin-bottom: 16px; }
.compare-block h4 { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.compare-row {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
}
.cr-bar {
  height: 8px;
  background: #0c1017;
  border-radius: 999px;
  overflow: hidden;
}
.cr-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.cr-val { white-space: nowrap; font-weight: 700; }
.lightbox-inner {
  position: relative;
  max-width: min(96vw, 1200px);
  max-height: 90vh;
}
.lightbox-inner img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 12px;
  display: block;
}
.lightbox-inner .modal-x {
  position: absolute;
  top: -12px;
  right: -12px;
  background: var(--card);
  border: 1px solid var(--line);
}
