/* ==========================================================================
   Lineage Garden (계보원) - Main Layout & Core UI Stylesheet
   Path: /linea/css/linea.css
   ========================================================================== */

:root {
  --bg: #edf2eb;
  --bg-dots: rgba(73, 94, 76, 0.12);
  --panel: #f7faf5;
  --panel-2: #e4ece1;
  --panel-card: #ffffff;
  --fg: #1d2b24;
  --muted: #576b60;
  --line: #cbd8c8;
  --line-strong: #92a792;
  --accent: #274c3e;            /* Deep Garden Pine */
  --accent-fg: #ffffff;
  --accent-soft: #dfebe2;
  --ochre: #9c6c2e;             /* Antique Ochre */
  --ochre-soft: #f4eadc;
  --celestial: #2b4c7e;         /* Lapis Blue */
  --celestial-soft: #e2ebf7;
  --danger: #a13d30;
  --ok: #2e7845;
  --shadow-sm: 0 2px 8px rgba(29, 43, 36, 0.06);
  --shadow: 0 8px 30px rgba(29, 43, 36, 0.12);
  --display: "Gowun Batang", "Noto Serif KR", serif;
  --body: "IBM Plex Sans KR", "Noto Sans KR", system-ui, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121815;
    --bg-dots: rgba(146, 175, 150, 0.15);
    --panel: #1a231f;
    --panel-2: #24302b;
    --panel-card: #1f2a25;
    --fg: #e5ede7;
    --muted: #95aaa0;
    --line: #2e3d36;
    --line-strong: #4a5e54;
    --accent: #5db98f;
    --accent-fg: #0d1a14;
    --accent-soft: #1d382c;
    --ochre: #e2ad63;
    --ochre-soft: #382c1a;
    --celestial: #7ba6e6;
    --celestial-soft: #1c2b42;
    --danger: #e27d70;
    --ok: #64b77f;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121815;
  --bg-dots: rgba(146, 175, 150, 0.15);
  --panel: #1a231f;
  --panel-2: #24302b;
  --panel-card: #1f2a25;
  --fg: #e5ede7;
  --muted: #95aaa0;
  --line: #2e3d36;
  --line-strong: #4a5e54;
  --accent: #5db98f;
  --accent-fg: #0d1a14;
  --accent-soft: #1d382c;
  --ochre: #e2ad63;
  --ochre-soft: #382c1a;
  --celestial: #7ba6e6;
  --celestial-soft: #1c2b42;
  --danger: #e27d70;
  --ok: #64b77f;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

/* Base resets & typography */
* { box-sizing: border-box; }
html {
  height: 100%;
}
body {
  min-height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.num { font-variant-numeric: tabular-nums; }

/* Garden App Container: Fixed to full viewport under navbar */
.linea-app {
  width: 100%;
  height: calc(100vh - 56px);
  min-height: 560px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* Garden Topbar */
.garden-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.brand-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-right: auto;
}
.brand-group .logo-leaf {
  color: var(--accent);
  font-size: 1.25rem;
}
.brand-group h1 {
  font-family: var(--display);
  font-size: 21px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--fg);
}
.brand-group .hanja {
  font-family: var(--display);
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
.brand-group .badge-garden {
  font-size: 11px;
  padding: 2px 7px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 600;
  margin-left: 4px;
}

/* View Switcher Tabs */
.view-tabs {
  display: flex;
  background: var(--panel-2);
  padding: 3px;
  border-radius: var(--radius-md);
  gap: 2px;
}
.view-tabs button {
  border: 0;
  background: transparent;
  padding: 6px 13px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}
.view-tabs button:hover {
  color: var(--fg);
}
.view-tabs button[aria-selected="true"] {
  background: var(--panel);
  color: var(--fg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.view-tabs button[data-view="indra"] {
  color: var(--ochre);
}
.view-tabs button[data-view="indra"][aria-selected="true"] {
  background: var(--ochre-soft);
  color: var(--ochre);
  font-weight: 700;
}

/* Status Chips */
.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.chip.ok {
  border-color: var(--ok);
  color: var(--ok);
  background: rgba(46, 120, 69, 0.08);
}
.chip.warn {
  border-color: var(--ochre);
  color: var(--ochre);
  background: var(--ochre-soft);
}
.chip.user-badge {
  border-color: var(--line-strong);
  color: var(--fg);
  background: var(--panel-2);
}

/* Layout: Shelf & Work Area */
.garden-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 0;
}

/* Left Shelf (서가 / 계보 목록) */
.shelf {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 14px;
  gap: 10px;
}
.shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.shelf-header h2 {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin: 0;
}
.shelf-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 6px;
  margin-bottom: 2px;
  padding-left: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.treelist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}
.treelist li button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.12s ease;
}
.treelist li button:hover {
  background: var(--panel-2);
}
.treelist li button[aria-current="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.treelist .tname {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 6px;
}
.treelist .tmeta {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.badge-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
}
.badge-tag.dynasty { background: var(--ochre-soft); color: var(--ochre); }
.badge-tag.family { background: var(--accent-soft); color: var(--accent); }
.badge-tag.org { background: var(--celestial-soft); color: var(--celestial); }

.shelf-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

/* Work Section */
.work {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.worktool {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.worktool .title {
  display: flex;
  flex-direction: column;
  margin-right: auto;
  min-width: 0;
}
.worktool .title h2 {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  color: var(--fg);
}
.worktool .title small {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}
.worktool .search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.worktool .search-box i {
  position: absolute;
  left: 9px;
  color: var(--muted);
  font-size: 12px;
}
.worktool input[type=search] {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 6px 10px 6px 28px;
  min-width: 180px;
  font-size: 13px;
  transition: border-color 0.15s;
}
.worktool input[type=search]:focus {
  border-color: var(--accent);
}

/* Button UI Components */
.btn-linea {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--fg);
  transition: all 0.12s ease;
}
.btn-linea:hover {
  background: var(--panel-2);
}
.btn-linea.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-linea.primary:hover {
  filter: brightness(1.1);
}
.btn-linea.danger {
  color: var(--danger);
  border-color: var(--danger);
}
.btn-linea.danger:hover {
  background: rgba(161, 61, 48, 0.08);
}
.btn-linea.small {
  padding: 4px 8px;
  font-size: 12px;
}
.btn-linea:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Stage & Panels */
.stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 350px;
  min-height: 0;
  min-width: 0;
}
.stage.nodetail {
  grid-template-columns: 1fr;
}
.view-area {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  position: relative;
  background: var(--bg);
}

/* Detail & Edit Sidebar */
.detail {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  gap: 12px;
}
.detail header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.detail header h3 {
  font-family: var(--display);
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}
.detail .ro {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.detail .ro .ttl-badge {
  color: var(--ochre);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.detail .ro .nm {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  margin-top: 2px;
  color: var(--fg);
}
.detail .ro .nm .hj {
  color: var(--muted);
  font-size: 16px;
  margin-left: 6px;
  font-weight: 400;
}
.detail dl {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: 13px;
}
.detail dt {
  color: var(--muted);
  font-weight: 500;
}
.detail dd {
  margin: 0;
  color: var(--fg);
  word-break: break-all;
}
.detail .notebox {
  font-size: 13px;
  line-height: 1.6;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--fg);
}
.detail .notebox .tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 4px;
  background: var(--ochre-soft);
  color: var(--ochre);
  font-weight: 600;
}
.detail .notebox .tag.se {
  background: var(--celestial-soft);
  color: var(--celestial);
}

/* Edit Form inside Detail Panel */
.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.form input, .form select, .form textarea {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  color: var(--fg);
  font-size: 13px;
  width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus {
  border-color: var(--accent);
}
.form textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
}
.form .row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.form .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 6px;
}
.empty-msg {
  color: var(--muted);
  font-size: 13px;
  padding: 10px 0;
  line-height: 1.5;
}
.detail .hint-card {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border-radius: var(--radius-sm);
  padding: 10px;
  line-height: 1.5;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 20, 18, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100020;
  padding: 16px;
}
.modal-overlay .box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-overlay h3 {
  font-family: var(--display);
  font-size: 19px;
  font-weight: 700;
  margin: 0;
}
.modal-overlay .box textarea {
  min-height: 180px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}
.modal-overlay .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* Toast */
.linea-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 100030;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastFade 0.2s ease-out;
}
@keyframes toastFade {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Responsive adjustments */
@media (max-width: 900px) {
  body { overflow: auto; }
  .garden-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .shelf {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .treelist {
    flex-direction: row;
    overflow-x: auto;
    flex: none;
    padding-bottom: 6px;
  }
  .treelist li {
    flex: none;
    max-width: 220px;
  }
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(55vh, 1fr) auto;
  }
  .detail {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
