:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e6ee;
  --text: #1c2033;
  --muted: #6b7280;
  --accent: #6366f1;
  --accent-soft: #eef0ff;
  --danger: #e5484d;
  --ok: #22a05a;
  --warn: #d99a06;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #171a23; --surface-2: #1f2330; --border: #2a2f3d;
    --text: #e7e9f0; --muted: #9097a8; --accent: #8b8ff8; --accent-soft: #23264a;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #171a23; --surface-2: #1f2330; --border: #2a2f3d;
  --text: #e7e9f0; --muted: #9097a8; --accent: #8b8ff8; --accent-soft: #23264a;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; word-break: break-all; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; margin: 0; }
.grow { flex: 1; }

/* buttons & inputs */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 8px 14px; font: inherit; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 6px 10px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; }
input[type=color] { padding: 2px; height: 38px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px; display: flex; flex-direction: column; gap: 12px; text-align: center; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; }
.login-card p { margin: 0 0 8px; }
.logo-lg { font-size: 44px; }

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-size: 18px; font-weight: 800; padding: 4px 10px 14px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer;
  color: var(--text); text-decoration: none; user-select: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); }
.side-title { font-size: 12px; color: var(--muted); padding: 14px 10px 4px; font-weight: 600; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 6px; }
.side-bottom { margin-top: auto; display: flex; gap: 4px; padding-top: 12px; border-top: 1px solid var(--border); }
.main { flex: 1; min-width: 0; padding: 0 24px 40px; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; gap: 8px; align-items: center; padding: 16px 0;
}
.topbar select { width: auto; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; }
.search input { border: none; outline: none; padding: 9px 0; background: transparent; }
.search:focus-within { border-color: var(--accent); }
.banner { background: #fff4d6; color: #7a5600; border: 1px solid #f3d27a; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
:root[data-theme="dark"] .banner { background: #3a2f10; color: #f3d27a; border-color: #6b5517; }
.only-mobile { display: none; }
.backdrop { display: none; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 26px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 13px; }
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel.span2 { grid-column: span 2; }
.panel-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-h h3 { margin: 0; font-size: 15px; }
.mini-list { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow-y: auto; }
.mini { display: flex; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 8px; cursor: pointer; min-width: 0; }
.mini:hover { background: var(--surface-2); }
.mini .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .s { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mini-empty { color: var(--muted); padding: 8px; font-size: 13px; }

/* cards */
.list-head { display: flex; align-items: baseline; gap: 10px; }
.list-head h2 { margin: 4px 0 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.cards.compact { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 10px;
  border-top: 4px solid var(--c, var(--accent)); transition: transform .12s, box-shadow .12s; min-width: 0;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(16,24,40,.1); }
.card-h { display: flex; gap: 10px; align-items: center; }
.card .ic { font-size: 26px; width: 40px; height: 40px; display: grid; place-items: center; background: var(--surface-2); border-radius: 10px; flex-shrink: 0; }
.card .nm { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { font-size: 12px; color: var(--muted); }
.card .desc { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em; margin: 0; }
.card-f { display: flex; align-items: center; gap: 6px; margin-top: auto; }
.card .pin { margin-left: auto; background: none; border: none; cursor: pointer; font-size: 16px; opacity: .35; padding: 2px; }
.card .pin.on { opacity: 1; }
.cards.compact .card .desc { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11.5px; padding: 2px 8px; background: var(--surface-2); border-radius: 999px; color: var(--muted); cursor: pointer; border: 1px solid transparent; }
.chip:hover, .chip.on { border-color: var(--accent); color: var(--accent); }
.badge { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.b-active { background: #dcfce7; color: #166534; }
.b-dev { background: #e0e7ff; color: #3730a3; }
.b-paused { background: #fef3c7; color: #92400e; }
.b-archived { background: #e5e7eb; color: #4b5563; }
:root[data-theme="dark"] .b-active { background: #14361f; color: #86efac; }
:root[data-theme="dark"] .b-dev { background: #23264a; color: #a5b4fc; }
:root[data-theme="dark"] .b-paused { background: #3a2f10; color: #fcd34d; }
:root[data-theme="dark"] .b-archived { background: #2a2f3d; color: #9ca3af; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .b-active { background: #14361f; color: #86efac; }
  :root:not([data-theme="light"]) .b-dev { background: #23264a; color: #a5b4fc; }
  :root:not([data-theme="light"]) .b-paused { background: #3a2f10; color: #fcd34d; }
  :root:not([data-theme="light"]) .b-archived { background: #2a2f3d; color: #9ca3af; }
  :root:not([data-theme="light"]) .banner { background: #3a2f10; color: #f3d27a; border-color: #6b5517; }
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; background: #a1a1aa; }
.dot.up { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,160,90,.15); }
.dot.down { background: var(--danger); box-shadow: 0 0 0 3px rgba(229,72,77,.15); }
.todo-cnt { font-size: 12px; color: var(--warn); font-weight: 600; }
.empty { text-align: center; padding: 60px 0; color: var(--muted); }

/* drawer */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(520px, 100vw); background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: -8px 0 32px rgba(0,0,0,.12); z-index: 20;
  transform: translateX(105%); transition: transform .22s ease; display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-h { display: flex; gap: 12px; align-items: center; padding: 18px 18px 10px; }
.d-icon { font-size: 30px; width: 52px; height: 52px; display: grid; place-items: center; background: var(--surface-2); border-radius: 14px; flex-shrink: 0; }
.d-title { flex: 1; min-width: 0; }
.d-title h2 { margin: 0; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.d-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 18px 12px; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { background: none; border: none; font: inherit; color: var(--muted); padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.tabs button .n { font-size: 11px; background: var(--surface-2); border-radius: 999px; padding: 0 6px; margin-left: 4px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px 40px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; align-items: start; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
.copy-row { display: flex; gap: 6px; align-items: center; }
.copy-row code { flex: 1; }
.prompt-box { background: var(--surface-2); border-radius: 10px; padding: 12px; white-space: pre-wrap; font-size: 13px; max-height: 300px; overflow-y: auto; margin-top: 6px; }
.note-add { display: flex; gap: 6px; margin-bottom: 14px; }
.note-add textarea { min-height: 40px; }
.note { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.note input[type=checkbox] { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; accent-color: var(--accent); }
.note .c { flex: 1; white-space: pre-wrap; word-break: break-word; min-width: 0; }
.note.done .c { text-decoration: line-through; color: var(--muted); }
.note .m { font-size: 11.5px; color: var(--muted); }
.note .x { background: none; border: none; color: var(--muted); cursor: pointer; opacity: 0; }
.note:hover .x { opacity: 1; }
.timeline .ev { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.timeline .ev .s { color: var(--muted); white-space: nowrap; font-size: 12px; }

/* dialogs */
dialog { border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); width: min(640px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10,12,20,.45); }
dialog form, .settings { padding: 22px; }
dialog h2 { margin: 0 0 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-height: 64vh; overflow-y: auto; padding: 2px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .w-icon { grid-column: 1 / 2; }
fieldset { border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; gap: 10px; padding: 12px; }
legend { padding: 0 6px; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.dlg-foot { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.set-row { display: flex; gap: 16px; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--border); }
.set-row.col { flex-direction: column; align-items: stretch; gap: 6px; }
.set-row p { margin: 2px 0 0; font-size: 13px; }
.backup-list { font-size: 12.5px; max-height: 160px; overflow-y: auto; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; transition: .2s; z-index: 100; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* mobile */
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .hide-mobile { display: none; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .main { padding: 0 16px 40px; }
  .topbar { flex-wrap: wrap; }
  .search { order: 5; flex-basis: 100%; }
  .topbar select { flex: 1; }
  .dash-grid { grid-template-columns: 1fr; }
  .panel.span2 { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }
}
