:root {
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
  color: #0f1e35;
  background: #f4f7fb;
  font-synthesis: none;
  --navy: #0c172a;
  --navy-soft: #152540;
  --accent: #119d91;
  --accent-dark: #087c74;
  --accent-soft: #e8f8f5;
  --border: #dce4ef;
  --muted: #6b7c96;
  --danger: #dc3545;
  --danger-soft: #fff0f1;
  --shadow: 0 22px 60px rgba(15, 30, 53, 0.12);
}

* { box-sizing: border-box; }

body { margin: 0; min-width: 320px; min-height: 100vh; background: #f4f7fb; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  position: relative;
  display: grid;
  min-height: 100vh;
  place-items: center;
  overflow: hidden;
  padding: 32px;
  background: #f4f7fb;
}

.ambient { position: absolute; border-radius: 999px; filter: blur(2px); pointer-events: none; }
.ambient-one { width: 520px; height: 520px; left: -180px; top: -180px; background: #dff2f1; }
.ambient-two { width: 440px; height: 440px; right: -120px; bottom: -190px; background: #e7eeff; }

.login-card {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(330px, 0.82fr) minmax(430px, 1.18fr);
  width: min(980px, 100%);
  min-height: 570px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: white;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  flex-direction: column;
  padding: 52px 48px;
  color: white;
  background: var(--navy);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 11px;
  color: white;
  background: var(--accent);
  font-size: 23px;
  font-weight: 700;
}

.brand-mark.small { width: 40px; height: 40px; border-radius: 10px; font-size: 21px; }
.eyebrow { margin: 44px 0 12px; color: #67e8d7; font-size: 12px; font-weight: 700; letter-spacing: 0.12em; }
.eyebrow.accent { margin: 0 0 10px; color: var(--accent-dark); }
.login-brand h1 { margin: 0; font-size: clamp(38px, 4vw, 48px); line-height: 1.13; letter-spacing: -0.035em; }
.brand-copy { max-width: 290px; margin: 30px 0 0; color: #aebdd1; font-size: 15px; line-height: 1.8; }
.secure-note { display: flex; align-items: center; gap: 10px; margin-top: auto; color: #d5dfec; font-size: 14px; }
.secure-note span, .online-pill span { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #19b477; box-shadow: 0 0 0 4px rgba(25, 180, 119, 0.12); }

.login-form { display: flex; flex-direction: column; justify-content: center; padding: 60px 64px; }
.login-form h2, .dialog h2 { margin: 0; color: var(--navy); font-size: 28px; letter-spacing: -0.025em; }
.muted { margin: 8px 0 0; color: var(--muted); line-height: 1.65; }
label { display: block; margin: 28px 0 9px; color: #21314a; font-size: 14px; font-weight: 650; }
label em { color: var(--danger); font-style: normal; }
input, textarea {
  width: 100%;
  border: 1px solid #d8e1ed;
  border-radius: 11px;
  outline: none;
  color: #12223b;
  background: #f8fafc;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
input { height: 50px; padding: 0 14px; }
textarea { padding: 13px 14px; resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); background: white; box-shadow: 0 0 0 4px rgba(17, 157, 145, 0.1); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 62px; }
.text-button { position: absolute; right: 8px; top: 7px; height: 36px; border: 0; color: var(--accent-dark); background: transparent; font-size: 13px; font-weight: 700; }
.login-form .button { margin-top: 26px; }
.login-domain { margin: auto 0 -24px; padding-top: 46px; text-align: center; color: #9aabc1; font-size: 12px; }
.form-error { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 13px; line-height: 1.5; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 700;
  transition: transform 0.15s, background 0.15s, border-color 0.15s, opacity 0.15s;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
.button.primary { color: white; background: var(--accent); }
.button.primary:hover:not(:disabled) { background: var(--accent-dark); }
.button.secondary { border-color: var(--border); color: #20314c; background: white; }
.button.subtle { border-color: #e1e7ef; color: #52647d; background: #f8fafc; }
.button.ghost { border-color: #34445e; color: #e7edf5; background: transparent; }
.button.danger { color: white; background: var(--danger); }
.button.wide { width: 100%; min-height: 50px; }
.button.compact { min-height: 36px; padding: 0 14px; font-size: 13px; }

.app-shell { min-height: 100vh; }
.topbar { display: flex; min-height: 76px; align-items: center; justify-content: space-between; padding: 0 max(24px, calc((100vw - 1440px) / 2)); border-bottom: 3px solid var(--accent); color: white; background: var(--navy); }
.topbar-brand { display: flex; align-items: center; gap: 14px; }
.topbar-brand strong, .topbar-brand span { display: block; }
.topbar-brand strong { font-size: 16px; }
.topbar-brand span { margin-top: 4px; color: #9fb0c8; font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.online-pill { display: flex; height: 40px; align-items: center; gap: 10px; padding: 0 15px; border: 1px solid #30425f; border-radius: 20px; color: #dce6f2; background: var(--navy-soft); font-size: 13px; }
.online-pill b { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.workspace { width: min(1440px, 100%); margin: 0 auto; padding: 36px 24px 60px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.page-heading h1 { margin: 0; color: var(--navy); font-size: 32px; letter-spacing: -0.03em; }
.summary-grid { display: grid; grid-template-columns: 0.8fr 1.35fr 1fr; gap: 16px; margin-top: 28px; }
.summary-card { min-width: 0; padding: 21px 23px; border: 1px solid var(--border); border-radius: 14px; background: white; box-shadow: 0 8px 24px rgba(34, 55, 85, 0.045); }
.summary-card span, .summary-card small { display: block; color: var(--muted); }
.summary-card span { font-size: 13px; }
.summary-card strong { display: block; overflow: hidden; margin-top: 9px; color: var(--navy); font-size: 26px; text-overflow: ellipsis; white-space: nowrap; }
.summary-card small { margin-top: 7px; font-size: 12px; }
.summary-card .namespace-value { font-family: "Cascadia Code", Consolas, monospace; font-size: 18px; }
.status-card strong { display: flex; align-items: center; gap: 9px; color: #138657; font-size: 19px; }
.status-card strong i { width: 10px; height: 10px; border-radius: 50%; background: #18aa6d; box-shadow: 0 0 0 5px rgba(24, 170, 109, 0.12); }

.data-panel { margin-top: 20px; overflow: hidden; border: 1px solid var(--border); border-radius: 15px; background: white; box-shadow: 0 10px 32px rgba(34, 55, 85, 0.05); }
.panel-toolbar { display: flex; min-height: 76px; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 18px; border-bottom: 1px solid #e7edf4; }
.search-form { display: flex; width: min(690px, 100%); gap: 9px; }
.search-box { position: relative; flex: 1; margin: 0; }
.search-box span { position: absolute; left: 14px; top: 10px; color: #8291a6; font-size: 22px; font-weight: 400; }
.search-box input { height: 44px; padding-left: 42px; }
.table-wrap { position: relative; min-height: 310px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 14px 18px; border-bottom: 1px solid #edf1f6; text-align: left; vertical-align: middle; }
th { color: #61728a; background: #f8fafc; font-size: 12px; font-weight: 750; letter-spacing: 0.025em; }
td { color: #23344e; font-size: 14px; }
tbody tr { transition: background 0.14s; }
tbody tr:hover { background: #f8fbfc; }
th:nth-child(1) { width: 44%; }
th:nth-child(2) { width: 22%; }
th:nth-child(3) { width: 20%; }
th.actions-column { width: 14%; text-align: right; }
.key-name { overflow-wrap: anywhere; color: #0d2b43; font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; font-weight: 650; }
.metadata-chip, .permanent-chip { display: inline-flex; max-width: 100%; align-items: center; padding: 4px 8px; border-radius: 6px; color: #49617d; background: #edf3f8; font-size: 12px; }
.metadata-chip { overflow: hidden; font-family: "Cascadia Code", Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.permanent-chip { color: #147a64; background: var(--accent-soft); }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-action { min-height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 7px; color: #52647d; background: white; font-size: 12px; font-weight: 700; }
.row-action.delete { border-color: #ffd9dd; color: #cc3344; background: #fff8f8; }
.loading-row { display: flex; height: 54px; align-items: center; gap: 10px; padding: 0 18px; color: var(--muted); font-size: 13px; }
.spinner { width: 17px; height: 17px; border: 2px solid #d4e2e3; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { display: grid; min-height: 310px; place-items: center; align-content: center; padding: 40px; text-align: center; }
.empty-icon { display: grid; width: 58px; height: 58px; place-items: center; border-radius: 16px; color: var(--accent-dark); background: var(--accent-soft); font-family: Consolas, monospace; font-weight: 800; }
.empty-state h3 { margin: 18px 0 6px; color: var(--navy); }
.empty-state p { max-width: 460px; margin: 0 0 20px; color: var(--muted); line-height: 1.7; }
.pagination { display: flex; min-height: 62px; align-items: center; justify-content: space-between; padding: 0 18px; border-top: 1px solid #e7edf4; color: var(--muted); font-size: 13px; }
.pagination div { display: flex; gap: 8px; }

.dialog { width: min(780px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: hidden; border: 0; border-radius: 17px; background: white; box-shadow: 0 30px 90px rgba(5, 15, 30, 0.28); }
.dialog::backdrop { background: rgba(8, 19, 36, 0.62); backdrop-filter: blur(3px); }
.editor-dialog form { max-height: calc(100vh - 32px); overflow-y: auto; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 22px 26px 18px; border-bottom: 1px solid #e8edf4; }
.dialog-header h2 { font-size: 24px; }
.icon-button { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid var(--border); border-radius: 9px; color: #63748b; background: #f8fafc; font-size: 24px; line-height: 1; }
.dialog-body { padding: 4px 26px 24px; }
.dialog-body label { margin-top: 20px; }
.label-row { display: flex; align-items: end; justify-content: space-between; }
.inline-action { padding: 5px 7px; border: 0; color: var(--accent-dark); background: transparent; font-size: 12px; font-weight: 700; }
.code-input { min-height: 230px; font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; line-height: 1.6; tab-size: 2; }
.field-hint { display: flex; justify-content: space-between; margin-top: 7px; color: #8796aa; font-size: 11px; }
.advanced-fields { margin-top: 18px; border: 1px solid #e2e8f0; border-radius: 10px; background: #fafbfd; }
.advanced-fields summary { padding: 13px 15px; cursor: pointer; color: #40536d; font-size: 13px; font-weight: 700; }
.advanced-grid { display: grid; grid-template-columns: 0.75fr 1.25fr; gap: 18px; padding: 0 15px 16px; border-top: 1px solid #e7ecf2; }
.advanced-grid label { margin-top: 15px; }
.advanced-grid small { display: block; margin-top: 6px; color: #8796aa; line-height: 1.5; }
.metadata-input { min-height: 76px; font-family: Consolas, monospace; font-size: 12px; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 26px; border-top: 1px solid #e8edf4; background: #fafbfd; }
.dialog-footer.centered { justify-content: center; margin-top: 24px; padding: 18px 0 0; background: transparent; }
.confirm-dialog { width: min(460px, calc(100vw - 32px)); padding: 30px; text-align: center; }
.danger-mark { display: grid; width: 54px; height: 54px; place-items: center; margin: 0 auto 16px; border-radius: 50%; color: var(--danger); background: var(--danger-soft); font-size: 26px; font-weight: 800; }
.confirm-dialog h2 { font-size: 23px; }
.confirm-dialog p { color: var(--muted); line-height: 1.65; }
.confirm-dialog code { display: block; max-height: 90px; overflow: auto; padding: 10px; border-radius: 8px; color: #8f2934; background: #fff4f5; overflow-wrap: anywhere; }

.toast-region { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: grid; gap: 10px; }
.toast { min-width: 260px; max-width: 390px; padding: 13px 16px; border: 1px solid #cfe7df; border-radius: 10px; color: #155d4d; background: #f0fbf7; box-shadow: 0 12px 30px rgba(22, 50, 70, 0.15); font-size: 13px; animation: toast-in 0.2s ease-out; }
.toast.error { border-color: #f1cbd0; color: #9d2937; background: #fff5f6; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.structured-editor-dialog { width: min(1120px, calc(100vw - 32px)); }
.structured-editor-dialog form { display: flex; max-height: calc(100vh - 32px); flex-direction: column; overflow: hidden; }
.structured-editor-dialog .dialog-body { overflow-y: auto; overscroll-behavior: contain; }
.structured-editor-dialog .dialog-footer { flex: 0 0 auto; }

.editor-mode-switch {
  display: inline-flex;
  width: fit-content;
  margin-top: 22px;
  padding: 4px;
  border: 1px solid #dfe7ef;
  border-radius: 11px;
  background: #f3f6f9;
}
.editor-mode-button {
  min-height: 35px;
  padding: 0 15px;
  border: 0;
  border-radius: 8px;
  color: #687990;
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}
.editor-mode-button.active { color: #0d726b; background: white; box-shadow: 0 2px 8px rgba(26, 52, 75, 0.1); }

.structured-editor { display: grid; gap: 16px; margin-top: 15px; }
.structured-editor[aria-busy="true"] { pointer-events: none; opacity: 0.55; }
.schema-note { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid #cceae4; border-radius: 11px; color: #175f58; background: #effaf7; }
.schema-note-icon { display: grid; width: 28px; height: 28px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: white; background: var(--accent); font-size: 14px; font-weight: 800; }
.schema-note strong, .schema-note small { display: block; }
.schema-note strong { font-size: 13px; }
.schema-note small { margin-top: 3px; color: #57817c; font-size: 11px; line-height: 1.5; }

.schema-section { overflow: hidden; border: 1px solid #dfe6ef; border-radius: 13px; background: #fff; }
.schema-section-header { display: flex; min-height: 72px; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 18px; border-bottom: 1px solid #e8edf3; background: #f8fafc; }
.schema-section-header > div { display: flex; align-items: center; gap: 12px; }
.schema-section-header h3 { margin: 0; color: #172a43; font-size: 16px; }
.schema-section-header p { margin: 4px 0 0; color: #74849a; font-size: 12px; line-height: 1.45; }
.section-index { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border-radius: 9px; color: var(--accent-dark); background: var(--accent-soft); font-family: Consolas, monospace; font-size: 12px; font-weight: 800; }
.account-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; padding: 18px; }
.account-grid label, .vin-identity label, .secret-grid label { margin: 0 0 7px; font-size: 12px; }
.account-grid input, .vin-identity input, .secret-grid input { height: 44px; }
.date-preview { display: block; overflow: hidden; margin-top: 6px; color: #8796aa; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.vins-meta-panel { margin: 15px 18px 0; border: 1px solid #e2e8f0; border-radius: 10px; background: #fafbfd; }
.vins-meta-panel summary { padding: 12px 14px; cursor: pointer; color: #52647d; font-size: 12px; font-weight: 750; }
.vins-meta-grid { grid-template-columns: 1fr 1fr; padding-top: 2px; border-top: 1px solid #e7ecf2; }
.vin-list { display: grid; gap: 14px; padding: 15px 18px 18px; }
.vin-card { overflow: hidden; border: 1px solid #dce5ee; border-radius: 12px; background: #fbfcfe; box-shadow: 0 5px 16px rgba(20, 43, 68, 0.035); }
.vin-card-header { display: flex; min-height: 54px; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 14px; border-bottom: 1px solid #e5ebf2; background: white; }
.vin-card-header > div:first-child { display: flex; min-width: 0; align-items: center; gap: 10px; }
.vin-card-header strong { overflow: hidden; color: #18304c; font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.vin-badge { flex: 0 0 auto; padding: 4px 7px; border-radius: 6px; color: #0b776d; background: #e7f7f4; font-size: 10px; font-weight: 800; letter-spacing: 0.04em; }
.vin-card-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; }
.danger-text { color: #c93749 !important; }
.vin-identity { padding: 14px 14px 0; }
.vin-identity input { color: #103557; background: white; font-family: "Cascadia Code", Consolas, monospace; font-weight: 700; letter-spacing: 0.025em; }
.secret-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 14px; }
.secret-grid input { background: white; font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
.custom-fields { margin: 0 14px 14px; border-top: 1px dashed #dbe3ec; }
.custom-fields summary { padding: 12px 0 8px; cursor: pointer; color: #687990; font-size: 12px; font-weight: 750; }
.custom-field-list { display: grid; gap: 8px; }
.custom-field-row { display: grid; grid-template-columns: minmax(130px, 0.8fr) minmax(180px, 1.8fr) 88px 32px; gap: 8px; }
.custom-field-row input, .custom-field-row select { height: 38px; }
.custom-field-row select { width: 100%; padding: 0 9px; border: 1px solid #d8e1ed; border-radius: 9px; outline: none; color: #40536d; background: white; }
.icon-button.tiny { width: 32px; height: 38px; border-radius: 8px; font-size: 18px; }
.add-field-button { margin-top: 9px; }
.vin-empty-state { display: flex; min-height: 150px; align-items: center; justify-content: center; flex-direction: column; gap: 6px; margin: 15px 18px 18px; border: 1px dashed #cfdbe7; border-radius: 11px; color: #718299; background: #fbfcfd; text-align: center; }
.vin-empty-state strong { color: #40536d; font-size: 14px; }
.vin-empty-state span { margin-bottom: 6px; font-size: 12px; }
.raw-editor { margin-top: 15px; }
.raw-warning { margin: 9px 0 0; color: #7d8ca0; font-size: 11px; line-height: 1.55; }

@media (max-width: 820px) {
  .login-shell { padding: 18px; }
  .login-card { grid-template-columns: 1fr; min-height: 0; }
  .login-brand { display: none; }
  .login-form { min-height: 590px; padding: 46px 34px; }
  .topbar { padding: 12px 18px; }
  .online-pill { display: none; }
  .workspace { padding: 28px 16px 44px; }
  .page-heading { align-items: start; }
  .summary-grid { grid-template-columns: 1fr; }
  .panel-toolbar { align-items: stretch; flex-direction: column; }
  .search-form { flex-wrap: wrap; }
  .search-box { min-width: 100%; }
  th:nth-child(1) { width: 55%; }
  th:nth-child(2), td:nth-child(2) { display: none; }
  th:nth-child(3) { width: 25%; }
  th.actions-column { width: 20%; }
  .row-actions { flex-direction: column; }
  .advanced-grid { grid-template-columns: 1fr; }
  .account-grid, .secret-grid { grid-template-columns: 1fr 1fr; }
  .custom-field-row { grid-template-columns: 1fr 1.5fr 80px 32px; }
}

@media (max-width: 520px) {
  .topbar-brand span { display: none; }
  .topbar-brand strong { max-width: 175px; font-size: 14px; }
  .page-heading { flex-direction: column; }
  .page-heading .button { width: 100%; }
  th:nth-child(3), td:nth-child(3) { display: none; }
  th:nth-child(1) { width: 70%; }
  th.actions-column { width: 30%; }
  .dialog-body, .dialog-header { padding-left: 18px; padding-right: 18px; }
  .dialog-footer { padding-left: 18px; padding-right: 18px; }
  .schema-section-header { align-items: flex-start; flex-direction: column; }
  .vehicle-header .button { width: 100%; }
  .account-grid, .secret-grid, .vins-meta-grid { grid-template-columns: 1fr; }
  .vin-card-header { align-items: flex-start; flex-direction: column; }
  .vin-card-actions { width: 100%; justify-content: flex-end; }
  .custom-field-row { grid-template-columns: 1fr 78px 32px; }
  .custom-field-value { grid-column: 1 / -1; grid-row: 2; }
  .custom-field-type { grid-column: 2; grid-row: 1; }
  .custom-field-row .icon-button { grid-column: 3; grid-row: 1; }
}
