:root {
  --bg: #15151a;
  --panel: #22222a;
  --panel-2: #2c2c36;
  --border: #3a3a48;
  --text: #e8e8ec;
  --muted: #888894;
  --accent: #5cb85c;
  --accent-hover: #4cae4c;
  --danger: #d9534f;
  --warning: #f0ad4e;
  --info: #4a8acb;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }

header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--border); height: 48px;
}
header h1 { font-size: 14px; margin: 0; color: var(--text); font-weight: 600; letter-spacing: 0.3px; }
header .spacer { flex: 1; }
header input[type="text"], header select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 5px 9px; font-size: 12px;
}
header input[type="text"] { width: 240px; }
header #ui-lang { width: 64px; padding: 5px 6px; font-size: 11px; text-align: center; }

button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 5px 10px; font-size: 12px; cursor: pointer;
  transition: background 0.1s;
}
button:hover { background: #38384a; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.info { background: var(--info); border-color: var(--info); color: #fff; }
button.info:hover { background: #3a7abb; }
button.danger { color: var(--danger); }
button.danger:hover { background: #3a2828; }
button.icon { padding: 3px 7px; font-size: 11px; flex: 0 0 auto; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

@property --col-left  { syntax: '<length>'; inherits: false; initial-value: 220px; }
@property --col-right { syntax: '<length>'; inherits: false; initial-value: 360px; }
main {
  display: grid;
  grid-template-columns: var(--col-left, 220px) 1fr var(--col-right, 360px);
  height: calc(100vh - 48px);
  transition: --col-left 0.22s linear, --col-right 0.22s linear;
}
main.left-collapsed  { --col-left: 28px; }
main.right-collapsed { --col-right: 28px; }
.left, .right { background: var(--panel); display: flex; flex-direction: column; min-width: 0; }
.left  { border-right: 1px solid var(--border); }
.right { border-left:  1px solid var(--border); }
.center{ display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.col-header {
  display: flex; flex-direction: row; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 38px;
}
.col-header .col-title {
  flex: 1; margin: 0; padding: 0;
  font-size: 10px; text-transform: uppercase;
  color: var(--muted); letter-spacing: 0.6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1;
}
.col-toggle {
  width: 22px; height: 22px; flex-shrink: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 12px; line-height: 1;
  color: var(--muted);
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.col-toggle:hover { color: var(--text); background: #38384a; }
.col-content { flex: 1; min-height: 0; overflow-y: auto; }
.left  .col-content { display: flex; flex-direction: column; }
.right .col-content { display: block; }
.left.collapsed  .col-title,
.right.collapsed .col-title { display: none; }
.left.collapsed  .col-content,
.right.collapsed .col-content { display: none; }
.left.collapsed  .col-header,
.right.collapsed .col-header { padding: 8px 3px; justify-content: center; }
.graph-wrap { position: relative; background: #0f0f14; flex: 1; min-height: 0; overflow: hidden; }
#graph-canvas { display: block; width: 100%; height: 100%; }

/* ---- Left column: events list ---- */
.left h3 { font-size: 10px; text-transform: uppercase; color: var(--muted); padding: 12px 14px 8px; margin: 0; letter-spacing: 0.6px; }
#events-list { flex: 1; overflow-y: auto; padding: 0 6px 12px; }
#events-list .event-item {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; margin-bottom: 2px;
  cursor: pointer; font-size: 12px; color: var(--text);
  border-radius: 4px;
}
#events-list .event-item:hover { background: var(--panel-2); }
#events-list .event-item.open { background: rgba(92, 184, 92, 0.12); color: var(--accent); }
#events-list .event-item.open .name { font-weight: 600; }
#events-list .event-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#events-list .empty { padding: 20px 14px; font-size: 11px; color: var(--muted); text-align: center; font-style: italic; }

/* ---- Tab bar ---- */
.tab-bar {
  display: flex; align-items: stretch;
  background: var(--panel-2); border-bottom: 1px solid var(--border);
  padding: 0 4px 0 0; height: 36px; flex-shrink: 0;
  overflow-x: auto;
}
.tab-bar .tab {
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px 0 14px;
  background: transparent; border: none;
  border-right: 1px solid #20202a;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 12px; color: var(--muted);
  cursor: pointer; white-space: nowrap;
  min-width: 120px; max-width: 240px;
  height: 100%;
}
.tab-bar .tab:hover { background: rgba(255,255,255,0.03); color: var(--text); }
.tab-bar .tab.active {
  background: var(--bg); color: var(--text);
  border-bottom-color: var(--accent);
}
.tab-bar .tab .name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tab-bar .tab .dirty { color: var(--warning); font-weight: bold; margin-right: 2px; }
.tab-bar .tab .close {
  font-size: 14px; padding: 0 5px; border-radius: 3px;
  color: var(--muted); line-height: 1;
}
.tab-bar .tab .close:hover { background: rgba(255,255,255,0.1); color: var(--danger); }
.tab-bar #add-tab {
  background: transparent; border: none; border-radius: 0;
  font-size: 16px; color: var(--muted); padding: 0 14px;
  height: 100%;
}
.tab-bar #add-tab:hover { color: var(--accent); background: transparent; }

/* ---- Meta panel (right) ---- */
.right section { border-bottom: 1px solid var(--border); padding: 12px 14px; }
.right h3 { font-size: 10px; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; letter-spacing: 0.6px; }
.right label { display: block; font-size: 11px; color: var(--muted); margin: 8px 0 3px; }
.right label:first-child, .right .row + label { margin-top: 0; }
.right input, .right select {
  width: 100%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 4px 6px; font-size: 12px;
}
.right input:focus, .right select:focus { outline: none; border-color: var(--accent); }
.right .row { display: flex; gap: 6px; margin-top: 4px; }
.right .row > * { flex: 1; min-width: 0; }
.right .row label { margin-top: 0; }
.right .list-item,
#conditions-modal .list-item { display: flex; gap: 4px; margin-bottom: 4px; align-items: center; }
.right .list-item input,
#conditions-modal .list-item input { flex: 1; min-width: 0; }
.right .npc-block, .right .cond-block,
#conditions-modal .cond-block {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 10px; margin-bottom: 8px;
}
.right .cond-head, .right .npc-head,
#conditions-modal .cond-head { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.right .cond-head,
#conditions-modal .cond-head { font-size: 11px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; }
.right .cond-head .spacer, .right .npc-head .spacer,
#conditions-modal .cond-head .spacer { flex: 1; }
.right .npc-head input { flex: 1; }
.right .add-row,
#conditions-modal .add-row { margin-top: 6px; padding: 4px 8px; font-size: 11px; width: auto; }
.right .checkbox { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.right .checkbox input { width: auto; }
.right .checkbox label { margin: 0; color: var(--text); font-size: 12px; }
.right .full-select,
#conditions-modal .full-select { margin-top: 4px; width: 100%; }
#conditions-modal input, #conditions-modal select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 5px 8px; font-size: 12px;
}
#conditions-modal input:focus,
#conditions-modal select:focus { outline: none; border-color: var(--accent); }
#conditions-modal .icon { padding: 4px 8px; font-size: 11px; flex: 0 0 auto; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-panel {
  position: relative;
  width: min(900px, 94vw);
  height: min(640px, 90vh);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.modal-header h2 { margin: 0; font-size: 14px; font-weight: 600; }
.modal-header .spacer { flex: 1; }
.modal-tabs { display: flex; gap: 0; padding: 0 4px; background: var(--panel-2); border-bottom: 1px solid var(--border); overflow-x: auto; min-height: 32px; flex-shrink: 0; }
.modal-tabs .modal-tab {
  background: transparent; border: none;
  border-bottom: 2px solid transparent; border-radius: 0;
  padding: 6px 12px; font-size: 12px; color: var(--muted);
  cursor: pointer; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.modal-tabs .modal-tab:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.modal-tabs .modal-tab.active { color: var(--text); border-bottom-color: var(--accent); background: var(--bg); }
.modal-tabs .modal-tab .close { color: var(--muted); padding: 0 2px; font-size: 13px; line-height: 1; }
.modal-tabs .modal-tab .close:hover { color: var(--danger); }

.modal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.modal-table-wrap { flex: 1; overflow: auto; min-height: 0; }
.i18n-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.i18n-table thead th {
  text-align: left; padding: 8px 12px;
  font-size: 10px; text-transform: uppercase;
  color: var(--muted); letter-spacing: 0.6px; font-weight: 600;
  background: var(--panel-2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
.i18n-table th:nth-child(1) { width: 38%; }
.i18n-table th:nth-child(3) { width: 36px; }
.i18n-table tbody tr { border-bottom: 1px solid #20202a; }
.i18n-table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.i18n-table td { padding: 3px 6px; vertical-align: middle; }
.i18n-table td.act { text-align: right; padding-right: 10px; }
.i18n-table td input {
  width: 100%;
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 3px;
  padding: 5px 8px;
  font-family: "JetBrains Mono", Menlo, Consolas, monospace; font-size: 12px;
}
.i18n-table td input:hover { border-color: var(--border); }
.i18n-table td input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.i18n-table td input::placeholder { color: #666672; font-style: italic; }
.i18n-table td.key-readonly {
  font-family: "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 12px; color: var(--muted);
  padding: 8px 14px; word-break: break-all;
}
.i18n-table .empty { text-align: center; color: var(--muted); padding: 28px 0; font-style: italic; }

.modal-add-bar { background: var(--panel-2); border-top: 1px solid var(--border); padding: 6px; flex-shrink: 0; }
.modal-add-bar button {
  width: 100%; padding: 7px; font-size: 12px; font-weight: 500;
  background: transparent; border: 1px dashed var(--border);
  color: var(--accent);
}
.modal-add-bar button:hover { background: var(--bg); border-color: var(--accent); }

.modal-footer {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; background: var(--panel-2);
  border-top: 1px solid var(--border); font-size: 11px; color: var(--muted);
}
.modal-footer .spacer { flex: 1; }
.modal-footer .count { color: var(--accent); font-weight: 600; }

/* ---- Assets modal ---- */
.assets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}
.asset-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  min-height: 130px;
}
.asset-card .thumb {
  width: 100%;
  height: 90px;
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  overflow: hidden;
}
.asset-card .thumb img {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.asset-card.map-card .thumb {
  background: var(--panel-2);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.6px;
}
.asset-card .name {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  word-break: break-all;
  line-height: 1.3;
}
.asset-card .delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid #444;
  color: var(--danger);
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1;
}
.asset-card .delete-btn:hover { background: var(--danger); color: #fff; }
.assets-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 30px;
  font-style: italic;
}

.ctx-menu {
  position: fixed; z-index: 10000;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 4px; min-width: 160px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.55);
  padding: 4px 0;
}
.ctx-menu.hidden { display: none; }
.ctx-item {
  padding: 6px 14px; font-size: 12px;
  cursor: pointer; color: var(--text);
  white-space: nowrap;
}
.ctx-item:hover { background: var(--panel-2); color: var(--accent); }
.ctx-item.danger:hover { color: var(--danger); }
.ctx-sep { border-top: 1px solid var(--border); margin: 4px 0; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #2a2a32; border: 1px solid var(--border); color: var(--text); padding: 8px 16px; border-radius: 4px; font-size: 12px; z-index: 9999; opacity: 0; transition: opacity 0.2s; pointer-events: none; box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
.toast.show { opacity: 1; }
.toast.error { border-color: var(--danger); color: #ffb3b0; }

input[type="file"] { display: none; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a48; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a58; }
