/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface2: #f8f8f6;
  --border: #e2e2dc;
  --border-strong: #c8c8c0;
  --text: #1a1a18;
  --text-muted: #5a5a55;
  --text-hint: #8a8a82;
  --accent: #185FA5;
  --accent-hover: #0C447C;
  --accent-light: #e6f1fb;
  --danger: #a32d2d;
  --danger-light: #fcebeb;
  --danger-border: #f09595;
  --success: #3b6d11;
  --success-light: #eaf3de;
  --success-border: #97c459;
  --warn: #854f0b;
  --warn-light: #faeeda;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --header-h: 60px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== HEADER ===== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-icon { font-size: 22px; }
.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.header-sub {
  font-size: 11px;
  color: var(--text-hint);
  margin-top: 1px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.autosave-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--success);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}
.autosave-indicator.visible { opacity: 1; }

/* ===== LAYOUT ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--header-h);
  max-width: 1280px;
  margin: 0 auto;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 24px 16px;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--text-hint);
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all .12s;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-light); color: var(--accent); font-weight: 500; }
.nav-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}
.nav-item.active .nav-num {
  background: var(--accent);
  color: #fff;
}
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}
.draft-status {
  font-size: 11px;
  color: var(--text-hint);
  padding: 0 8px;
  margin-bottom: 8px;
}
.btn-load {
  display: block;
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: all .12s;
}
.btn-load:hover { border-color: var(--border-strong); color: var(--text); }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  padding: 32px 40px;
  min-width: 0;
}

/* ===== STATUS BAR ===== */
.status-bar {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 20px;
  font-weight: 500;
}
.status-bar.ok {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid var(--success-border);
}
.status-bar.err {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}
.status-bar.warn {
  background: var(--warn-light);
  color: var(--warn);
  border: 1px solid #fac775;
}

/* ===== RESTORE BANNER ===== */
@keyframes bannerSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.restore-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: #fff;
  border: 1px solid #9dc4ec;
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(24, 95, 165, .10);
  animation: bannerSlideIn .2s ease;
}
.restore-banner-icon {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.restore-banner-body { flex: 1; min-width: 0; }
.restore-banner-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.restore-banner-date {
  font-size: 12px;
  color: var(--text-hint);
}
.restore-banner-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-restore-yes {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s;
}
.btn-restore-yes:hover { background: var(--accent-hover); }
.btn-restore-no {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all .12s;
}
.btn-restore-no:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface2); }

/* ===== PANELS ===== */
.panel { display: none; }
.panel.active { display: block; }

/* ===== SECTION HEADER ===== */
.section-header { margin-bottom: 24px; }
.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.section-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.card-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-hint);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ===== FORM FIELDS ===== */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.req { color: #c0392b; margin-left: 2px; }
.opt {
  font-size: 10px;
  color: var(--text-hint);
  font-weight: 400;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
  appearance: none;
  -webkit-appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%238a8a82' stroke-width='1.5' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 95, 165, .1);
}
.field input:invalid:not(:placeholder-shown) {
  border-color: var(--danger);
}
.field textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}
.hint {
  font-size: 11px;
  color: var(--text-hint);
  margin-top: 4px;
  line-height: 1.4;
}

/* ===== GRID LAYOUTS ===== */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

@media (max-width: 900px) {
  .row2 { grid-template-columns: 1fr; }
  .row3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .row3 { grid-template-columns: 1fr; }
  .main-content { padding: 20px; }
  .sidebar { width: 180px; }
}

/* ===== REPEATABLE BLOCKS ===== */
.repeatable {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 12px;
  position: relative;
}
.repeatable-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.repeatable-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.repeatable-sub {
  font-size: 11px;
  color: var(--text-hint);
  margin-top: 2px;
}
.btn-remove {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-md);
  color: var(--danger);
  background: transparent;
  cursor: pointer;
  transition: all .12s;
}
.btn-remove:hover { background: var(--danger-light); }

/* ===== BUTTONS ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
}
.btn-outline:hover { border-color: var(--border-strong); background: var(--surface2); }

.btn-add {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  margin-bottom: 20px;
  transition: all .12s;
}
.btn-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* ===== PANEL NAVIGATION ===== */
.panel-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ===== CHAR COUNTER ===== */
.char-counter {
  font-size: 11px;
  color: var(--text-hint);
  text-align: right;
  margin-top: 3px;
}
.char-counter.near { color: var(--warn); }
.char-counter.full { color: var(--danger); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-hint);
  font-size: 13px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
}
.empty-state svg { margin-bottom: 8px; opacity: .4; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-hint); }
