/* 카페 자동화 — 기존 프로그램의 서버화
 *
 * 본 화면 = 구글시트를 대신하는 서버 시트 (탭 전부 + 셀 읽기/쓰기)
 * PC 창   = 기존 프로그램(네이버 카페 마케팅 프로그램, 950x960)을 그대로 옮긴 창
 *
 * 새로 지어내지 않는다. 있는 것을 옮긴다.
 */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1b1b1b;
  --muted: #6b7280;
  --line: rgba(128, 128, 128, .26);
  --line-strong: rgba(128, 128, 128, .45);
  --panel: rgba(128, 128, 128, .08);
  --accent: #2563eb;
  --sel: rgba(37, 99, 235, .12);
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --row-h: 24px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16181c; --fg: #e6e6e6; --muted: #9aa0a6; --panel: rgba(255,255,255,.06); }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: system-ui, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 14px; line-height: 1.45; overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.error { color: var(--bad); min-height: 1.2em; margin: .4rem 0 0; font-size: 13px; }
.spacer { flex: 1; }
button.link { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }

/* ---- 로그인 ---- */
.login-wrap { display: grid; place-items: center; height: 100%; }
.login-box {
  width: 320px; padding: 1.6rem; border: 1px solid var(--line); border-radius: 10px;
  display: flex; flex-direction: column; gap: .3rem;
}
.login-box h1 { font-size: 1.2rem; margin: 0; }
.login-box p { margin: 0; }
.login-box label { display: flex; flex-direction: column; gap: .25rem; font-size: 13px; margin-top: .5rem; }
.login-box input, .login-box button {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 6px; background: transparent; color: inherit;
}
.login-box button {
  margin-top: .8rem; font-weight: 600; border: 0; background: var(--accent); color: #fff; cursor: pointer;
}

/* ---- 본 화면 틀 ---- */
#app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .45rem .8rem;
  border-bottom: 1px solid var(--line); flex: none;
}
.brand { font-weight: 700; }
.pick { display: flex; align-items: center; gap: .35rem; font-size: 13px; color: var(--muted); }
.pick select {
  font: inherit; padding: .22rem .4rem; border: 1px solid var(--line);
  border-radius: 5px; background: transparent; color: inherit; max-width: 240px;
}

/* ---- 시트 탭 줄 ---- */
.sheettabs {
  display: flex; gap: 1px; padding: 0 .5rem; flex: none;
  border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap;
}
.sheettabs::-webkit-scrollbar { height: 6px; }
.sheettabs button {
  font: inherit; font-size: 12.5px; padding: .38rem .7rem; border: 0;
  background: none; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; flex: none;
}
.sheettabs button:hover { color: var(--fg); }
.sheettabs button.on { color: var(--fg); font-weight: 700; border-bottom-color: var(--accent); }
.sheettabs .cnt { font-size: 11px; opacity: .55; margin-left: .3rem; }

/* ---- 표 ---- */
.sheetmain { flex: 1; min-height: 0; padding: 0; position: relative; }
.gridbox { display: flex; flex-direction: column; height: 100%; }
.grid-head { overflow: hidden; flex: none; background: var(--panel); border-bottom: 1px solid var(--line-strong); }
.grid-body { overflow: auto; flex: 1; min-height: 0; }
.grid-body:focus { outline: none; }
.grid-row { display: flex; height: var(--row-h); align-items: stretch; white-space: nowrap; }
#head-cols { height: 18px; }
#head-cols .grid-cell { font-size: 10.5px; color: var(--muted); justify-content: center; }
#head-names .grid-cell { font-weight: 700; }
.grid-cell {
  flex: none; padding: 0 .4rem; overflow: hidden; text-overflow: ellipsis;
  border-right: 1px solid var(--line); font-size: 12px;
  display: flex; align-items: center; user-select: none;
}
.header-cell { gap: .2rem; padding-right: .16rem; }
.header-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.filter-btn {
  width: 18px; height: 18px; flex: none; padding: 0; border: 0; border-radius: 3px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 9px;
  opacity: .62;
}
.filter-btn:hover { background: var(--sel); color: var(--accent); opacity: 1; }
.filter-btn.on { background: var(--accent); color: #fff; opacity: 1; }
.grid-body .grid-row:nth-child(even) { background: rgba(128,128,128,.035); }
.grid-cell.rownum {
  color: var(--muted); justify-content: flex-end; background: var(--panel);
  position: sticky; left: 0; z-index: 2; font-variant-numeric: tabular-nums;
}
.grid-cell.sel { background: var(--sel); }
.grid-cell.sel-top { border-top: 2px solid var(--accent); }
.grid-cell.sel-bottom { border-bottom: 2px solid var(--accent); }
.grid-cell.sel-left { border-left: 2px solid var(--accent); }
.grid-cell.sel-right { border-right: 2px solid var(--accent); }
.grid-cell.sel-active { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.grid-cell.editing { padding: 0; }
.grid-cell input {
  width: 100%; height: 100%; font: inherit; font-size: 12px; border: 0;
  outline: 2px solid var(--accent); outline-offset: -2px;
  background: var(--bg); color: var(--fg); padding: 0 .4rem;
}
.grid-spacer { width: 1px; }
.empty { padding: 2rem; color: var(--muted); }

/* 머리글의 값 필터 */
.filter-menu {
  position: fixed; z-index: 100; width: 284px; max-height: min(470px, calc(100vh - 16px));
  display: flex; flex-direction: column; gap: .45rem; padding: .65rem;
  color: var(--fg); background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: 8px; box-shadow: 0 12px 32px rgba(0,0,0,.22);
}
.filter-title { font-size: 12.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-search {
  width: 100%; padding: .38rem .5rem; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 5px; font: inherit; font-size: 12.5px;
}
.filter-search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.filter-quick { display: flex; gap: .35rem; }
.filter-menu button {
  padding: .3rem .5rem; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 5px; font: inherit; font-size: 12px; cursor: pointer;
}
.filter-menu button:hover { border-color: var(--line-strong); }
.filter-values {
  min-height: 90px; max-height: 270px; overflow: auto; border: 1px solid var(--line);
  border-radius: 5px; padding: .2rem 0;
}
.filter-value { display: flex; align-items: center; gap: .42rem; padding: .22rem .42rem; font-size: 12px; }
.filter-value:hover { background: var(--panel); }
.filter-value span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-note { min-height: 1em; }
.filter-footer { display: flex; justify-content: flex-end; gap: .4rem; padding-top: .15rem; }
.filter-footer .filter-clear { margin-right: auto; color: var(--muted); background: transparent; }
.filter-footer .filter-apply { color: #fff; background: var(--accent); border-color: var(--accent); }

.statusbar {
  display: flex; align-items: center; gap: .8rem; padding: .3rem .8rem;
  border-top: 1px solid var(--line); flex: none;
}
.status-action {
  padding: .18rem .45rem; color: var(--fg); background: var(--panel);
  border: 1px solid var(--line); border-radius: 4px; font: inherit; font-size: 11.5px;
  cursor: pointer;
}
.status-action:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.status-action:disabled { opacity: .4; cursor: default; }

/* ---- PC 프로그램 창 ----
   색은 customtkinter 기본 테마(파랑)의 값을 그대로 옮겼다.
   기존 프로그램은 set_appearance_mode 를 지정하지 않아 시스템을 따르므로
   밝은/어두운 두 벌을 모두 둔다. */
.pcwin {
  --ctk-bg: #EBEBEB;        /* CTk 창 배경  (어두울 때 #242424) */
  --ctk-frame: #DBDBDB;     /* CTkFrame     (어두울 때 #2B2B2B) */
  --ctk-entry: #F9F9FA;     /* CTkEntry     (어두울 때 #343638) */
  --ctk-entry-b: #979DA2;   /* 입력칸 테두리 (어두울 때 #565B5E) */
  --ctk-text: #DCE4EE;      /* 색 버튼 위의 글자색 */
  --ctk-fg: #1a1a1a;        /* 일반 글자     (어두울 때 #DCE4EE) */
  --ctk-log: #F9F9FA;       /* CTkTextbox   (어두울 때 #1D1E1E) */
  --ctk-seg: #979DA2;       /* 탭 선택 표시  (어두울 때 #4A4D50) */
}
@media (prefers-color-scheme: dark) {
  .pcwin {
    --ctk-bg: #242424; --ctk-frame: #2B2B2B; --ctk-entry: #343638;
    --ctk-entry-b: #565B5E; --ctk-fg: #DCE4EE; --ctk-log: #1D1E1E;
    --ctk-seg: #4A4D50;
  }
}
.pcwin {
  position: fixed; width: 950px; max-width: 96vw; height: 700px; max-height: 90vh;
  background: var(--ctk-bg); color: var(--ctk-fg);
  border: 1px solid var(--line-strong); border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0,0,0,.28); display: flex; flex-direction: column;
  z-index: 50; overflow: hidden;
}
.pcwin .bar {
  display: flex; align-items: center; gap: .6rem; padding: .4rem .6rem;
  background: var(--ctk-frame); border-bottom: 1px solid var(--line);
  cursor: move; flex: none;
}
.pcwin .bar .t { font-weight: 700; font-size: 13px; }
.pcwin .bar .x { font-size: 15px; line-height: 1; }
.pcwin .tabs { display: flex; gap: .15rem; padding: 0 .5rem; border-bottom: 1px solid var(--line); flex: none; }
.pcwin .tabs button {
  font: inherit; font-size: 12.5px; font-weight: 600; padding: .4rem .8rem; border: 0;
  background: none; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.pcwin .tabs button { color: var(--ctk-fg); opacity: .55; }
.pcwin .tabs button.on {
  opacity: 1; background: var(--ctk-seg); color: var(--ctk-text);
  border-radius: 6px 6px 0 0; border-bottom-color: transparent;
}
.pcwin .body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; padding: .5rem .6rem; gap: .35rem; }
.pcwin .ptab { display: none; flex: 1; min-height: 0; flex-direction: column; gap: .35rem; }
.pcwin .ptab.on { display: flex; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.row .lbl { font-size: 12px; color: var(--muted); margin-left: .4rem; }
.row input.mini { width: 56px; }
.row input.small { width: 96px; }
.row input, .row select {
  font: inherit; font-size: 12px; height: 28px; padding: 0 .4rem;
  border: 1px solid var(--ctk-entry-b); border-radius: 6px;
  background: var(--ctk-entry); color: var(--ctk-fg);
}
.row .lbl { color: var(--ctk-fg); opacity: .75; }
.row button.ctk {
  font: inherit; font-size: 12px; font-weight: 600; height: 28px; padding: 0 .7rem;
  border: 0; border-radius: 6px; color: var(--ctk-text); cursor: pointer;
  transition: background .12s;
}
.row button.ctk:disabled { opacity: .45; cursor: not-allowed; }

.cafelist {
  border: 0; border-radius: 6px; height: 210px; overflow: auto; flex: none;
  background: var(--ctk-frame);
}
.cl-row { display: flex; height: 22px; align-items: center; font-size: 12px; border-bottom: 1px solid var(--line); }
.cl-row.head { font-weight: 700; background: var(--ctk-seg); color: var(--ctk-text);
  position: sticky; top: 0; }
.cl-row.sum { font-weight: 700; color: var(--bad); }
.cl-c { flex: none; padding: 0 .35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-c.n { text-align: right; }

.loghead {
  display: flex; align-items: center; gap: .5rem; padding: .25rem .6rem;
  border-top: 1px solid var(--line); font-size: 12px; font-weight: 700; flex: none;
}
.loghead .lbl { font-weight: 400; }
.logbox {
  height: 150px; flex: none; margin: 0 .6rem .6rem;
  border: 1px solid var(--ctk-entry-b); border-radius: 6px;
  background: var(--ctk-log); color: var(--ctk-fg); padding: .4rem .5rem; overflow: auto;
  font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; white-space: pre-wrap;
}
.pcstate { font-size: 11.5px; font-weight: 700; }
.pcstate.idle { color: var(--muted); }
.pcstate.working { color: var(--ok); }
.pcstate.ip_change { color: var(--warn); }
.pcstate.offline { color: var(--bad); }

/* ── 대시보드 (로그인 첫 화면) ──────────────────────────────
   보기 전용이다. 시트별로 카드 하나, 카드 안에 그 시트가 맡은 PC 들이 한 줄씩. */
.dash { padding: 16px; overflow: auto; flex: 1; }
.dash-card {
  background: #fff; border: 1px solid #dadce0; border-radius: 8px;
  padding: 12px 14px; margin: 0 0 12px 0; max-width: 1100px;
}
.dash-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 600; }
.dash-name {
  background: none; border: none; padding: 0; font: inherit; font-weight: 600;
  color: #1a73e8; cursor: pointer;
}
.dash-name:hover { text-decoration: underline; }
.dash-pc {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 4px; border-top: 1px solid #f1f3f4;
}
.dash-pc-name { min-width: 140px; }
.dash-pc .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ── 시그마 표시 ────────────────────────────────────────────
   왼쪽 위 로고와 이름은 한 덩어리다. 누르면 대시보드로 간다. */
.brand {
  display: flex; align-items: center; gap: 7px;
  background: none; border: none; padding: 0 4px 0 0;
  font: inherit; font-weight: 700; color: #202124; cursor: pointer;
}
.brand:hover span { text-decoration: underline; }
.brand-logo { width: 22px; height: 22px; border-radius: 5px; display: block; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.login-logo { width: 34px; height: 34px; border-radius: 8px; }

/* ── 시트 색 고르기 ────────────────────────────────────────
   조각을 눌러 바로 칠한다. 대화상자를 여는 방식은 쓰기 나빠서 걷어냈다. */
.sheet-colors { display: inline-flex; align-items: center; gap: 10px; margin: 0 6px; }
.sheet-colgroup { display: inline-flex; align-items: center; gap: 3px; }
.sheet-swatch {
  width: 17px; height: 17px; padding: 0; border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, .28); cursor: pointer; display: block;
}
.sheet-swatch:hover { outline: 2px solid #1a73e8; outline-offset: 1px; }

/* ── 내려둔 팝업 띠 ────────────────────────────────────────
   팝업을 닫지 않고 잠깐 치워 둘 자리. 눌러서 다시 올린다. */
.sigma-tray {
  position: fixed; left: 10px; bottom: 8px; z-index: 3400;
  display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none;
}
.sigma-chip {
  pointer-events: auto;
  background: #242424; color: #eee; border: 1px solid #666; border-radius: 6px;
  padding: 5px 11px; font-size: 12px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
}
.sigma-chip:hover { background: #333; }
.sigma-min {
  border: 0; border-radius: 6px; color: #fff; background: #555;
  padding: 8px 12px; cursor: pointer; margin-left: auto;
}
.seed-top .sigma-min, .seed-result-head .sigma-min { margin-left: 0; }

/* ── 바꾸기 전 확인창 ──────────────────────────────────────
   브라우저 confirm 은 쓰지 않는다. 페이지를 통째로 멈추고,
   무엇이 닫히는지 함께 보여 줄 수 없기 때문이다. */
.ask-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 4500;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.ask-box {
  width: min(460px, 94vw); background: #fff; border-radius: 9px;
  padding: 18px 20px; box-shadow: 0 18px 60px rgba(0,0,0,.35); font-size: 13px;
}
.ask-box h4 { margin: 0 0 10px; font-size: 15px; }
.ask-line { margin: 5px 0; color: #444; line-height: 1.55; }
.ask-bar { display: flex; gap: 10px; justify-content: flex-end; margin-top: 15px; }
.ask-bar .strong { font-weight: 700; color: #c0392b; }
