:root {
  --navy: #182B5B;
  --navy-dark: #122145;
  --pink: #EF0769;
  --pink-dark: #c50657;
  --sky: #5597D8;
  --bg: #f5f6fa;
  --panel: #ffffff;
  --text: #172644;
  --muted: #6c7688;
  --line: #e4e8f0;
  --soft: #f1f4f9;
  --field: #ffffff;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', Inter, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 7px 13px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel); color: var(--text); font-weight: 500;
}
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-pink { background: var(--pink); color: #fff; border-color: var(--pink); }
.btn-quiet { background: transparent; border-color: transparent; }
.btn-add {
  justify-self: start; font-size: 12px; border: 1px dashed var(--line);
  border-radius: 7px; background: transparent; padding: 7px 10px; color: var(--muted);
}

input, textarea {
  width: 100%; background: var(--field); border: 1px solid var(--line);
  border-radius: 6px; padding: 9px 10px;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, textarea:focus {
  outline: 2px solid rgba(239,7,105,.35); outline-offset: 1px;
}

/* Login */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px 28px; display: grid; gap: 14px; box-shadow: 0 10px 30px rgba(23,38,68,.08);
}
.brand-logo img { height: 34px; display: block; }
.brand-logo-small img { height: 24px; }
.login-subtitle { margin: -8px 0 4px; color: var(--muted); font-size: 13px; }
.login-card label { display: grid; gap: 5px; font-size: 12px; font-weight: 600; }
.form-error { color: var(--pink-dark); font-size: 12px; margin: 0; }

/* App shell */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 14px 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-label { color: var(--muted); font-size: 13px; border-left: 1px solid var(--line); padding-left: 14px; }
.account { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.shell { flex: 1; display: grid; grid-template-columns: 170px minmax(0,1fr); min-height: 0; }
.sidenav {
  background: var(--panel); border-right: 1px solid var(--line); padding: 18px 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.nav-btn {
  width: 100%; justify-content: flex-start; border: 1px solid transparent; border-radius: 7px;
  background: transparent; padding: 9px 11px; text-align: left; font-size: 13px; color: var(--text);
}
.nav-btn.active { background: var(--soft); font-weight: 600; }
.work { min-width: 0; overflow: auto; }

.titlebar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 22px 24px 16px;
}
.crumb { display: flex; gap: 6px; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.titlebar h1 { font-size: 19px; margin: 0; font-weight: 600; }
.save-status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; margin-top: 6px; }
.retry-link { border: 0; background: transparent; color: var(--pink-dark); font-size: 11px; font-weight: 600; padding: 0; text-decoration: underline; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #339c74; }
.dot.saving { background: #d8a73b; }
.dot.error { background: var(--pink-dark); }
.actions { display: flex; gap: 7px; flex-wrap: wrap; }

.versionbar {
  display: flex; align-items: center; justify-content: space-between; margin: 0 24px 14px;
  border-bottom: 1px solid var(--line);
}
.languages { display: flex; gap: 18px; }
.languages button {
  border: 0; border-radius: 0; padding: 10px 0 11px; background: transparent; color: var(--muted); font-size: 13px;
}
.languages button[aria-selected=true] { color: var(--text); box-shadow: inset 0 -2px var(--pink); font-weight: 600; }
.lang-dot { width: 5px; height: 5px; border-radius: 50%; background: #339c74; display: inline-block; margin-left: 4px; }

.history-panel { margin: 0 24px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.history-panel h2 { font-size: 15px; margin: 0 0 12px; }
.history-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.history-row:first-child { border-top: 0; }
.history-row strong { font-size: 12.5px; }
.history-row p { font-size: 11.5px; color: var(--muted); margin: 3px 0 0; }
.history-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.history-actions .btn { font-size: 11.5px; min-height: 30px; padding: 5px 8px; }

.editor-grid { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,.92fr); gap: 16px; padding: 0 24px 26px; align-items: start; }
@media (max-width: 900px) { .editor-grid { grid-template-columns: 1fr; } }

.editor-form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: clip; }
.editor-form details { border-bottom: 1px solid var(--line); }
.editor-form details:last-child { border-bottom: 0; }
.editor-form summary { padding: 14px 16px; font-size: 12.5px; font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.editor-form summary::-webkit-details-marker { display: none; }
.editor-form summary:after { content: '+'; color: var(--muted); font-weight: 400; }
.editor-form details[open] > summary:after { content: '−'; }
.count { background: var(--soft); border-radius: 4px; padding: 1px 6px; font-size: 10px; margin-left: 6px; color: var(--muted); }
.section { padding: 0 16px 16px; display: grid; gap: 11px; }
.section label { display: grid; gap: 5px; font-size: 11.5px; font-weight: 600; }
.section label em { font-style: normal; color: var(--pink); margin-left: 3px; }
.section label .field-label { display: inline-block; }
.pair-title { display: grid; grid-template-columns: 1fr 1fr 20px 20px 20px; gap: 5px; color: var(--muted); font-size: 10px; }
.pair-row { display: grid; grid-template-columns: 1fr 1fr 20px 20px 20px; gap: 5px; align-items: center; margin-bottom: 7px; }
.pair-row input { font-size: 12px; padding: 8px; }
.remove-row, .row-move { padding: 0; border: 0; background: transparent; color: var(--muted); width: 20px; min-height: 30px; font-size: 12px; }
.row-move:disabled { opacity: .25; }
.drag-handle { cursor: grab; color: var(--muted); }

.preview-area { min-width: 0; position: sticky; top: 18px; }
.preview-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.preview-title { font-size: 12px; font-weight: 600; }
.preview-toolbar .btn { font-size: 11px; min-height: 30px; padding: 5px 9px; }
.preview-frame-wrap {
  background: var(--soft); border: 1px solid var(--line); border-radius: 9px; padding: 10px;
  aspect-ratio: 595/842; position: relative; overflow: hidden;
}
#preview-frame { width: 100%; height: 100%; border: 0; border-radius: 4px; background: #fff; }
.preview-empty {
  position: absolute; inset: 10px; display: flex; align-items: center; justify-content: center;
  text-align: center; color: var(--muted); font-size: 12px; padding: 20px; background: #fff; border-radius: 4px;
}
.preview-status { font-size: 11px; color: var(--muted); margin: 9px 1px 0; min-height: 15px; }

.library { padding: 0 24px 30px; }
.library-search { max-width: 340px; margin-bottom: 18px; }
.sheet-list { display: grid; gap: 10px; }
.sheet-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; flex-wrap: wrap; }
.sheet-card h3 { font-size: 14px; margin: 0 0 5px; font-weight: 600; }
.sheet-card p { font-size: 11px; color: var(--muted); margin: 0; }
.tag { display: inline-flex; align-items: center; background: var(--soft); border-radius: 4px; padding: 2px 6px; font-size: 10px; margin-right: 5px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty-state { padding: 24px; text-align: center; color: var(--muted); }

.toast { padding: 9px 24px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); font-size: 11.5px; min-height: 34px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(18,33,69,.45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal { background: var(--panel); border-radius: 12px; padding: 22px; width: 100%; max-width: 480px; max-height: 80vh; overflow: auto; }
.modal h2 { margin-top: 0; font-size: 16px; }
.modal-actions { margin-top: 14px; display: flex; justify-content: flex-end; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidenav { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 14px; }
  .nav-btn { width: auto; }
}
