/* 색·간격은 app/theme.py 값을 그대로 가져왔다 — PC 위젯과 같은 인상을 준다. */
:root {
  --panel: #17181C;
  --surface: #232630;
  --surface-hover: #2B2F3A;
  --border: #2E313A;
  --text: #E8E9ED;
  --muted: #9BA0AB;
  --focus: #C6CBD6;
  --warning: #D98E48;
  --danger: #E2796A;
  --done: #6E727C;
  --calendar: #7C8DA6;
  --xs: 4px; --sm: 8px; --md: 12px; --lg: 16px; --xl: 24px;
  --radius: 12px;
  --accent: #D98E48;
}

* { box-sizing: border-box; }

/* display를 지정한 요소는 hidden 속성만으로 숨겨지지 않는다.
   UA 스타일시트의 display:none 보다 아래 규칙들이 우선하기 때문이다. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--panel);
  color: var(--text);
  font: 15px/1.5 Pretendard, Inter, -apple-system, "Malgun Gothic", sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100dvh;
}

input, textarea, button { font: inherit; color: inherit; }

/* --- 로그인 ------------------------------------------------------------- */
#login form {
  display: flex; flex-direction: column; gap: var(--md);
  max-width: 360px; margin: 0 auto; padding: 15dvh var(--xl) var(--xl);
}
#login h1 { margin: 0; font-size: 28px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.error { margin: 0; color: var(--danger); font-size: 13px; min-height: 1.5em; }

#login input {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--md); min-height: 48px;
}
#login input:focus { outline: none; border-color: var(--focus); }

#login button {
  background: var(--warning); color: #1B1408; border: none;
  border-radius: var(--radius); padding: var(--md); min-height: 48px;
  font-weight: 600;
}
#login button:disabled { opacity: .6; }

.guide-link {
  color: var(--muted); font-size: 13px; text-align: center;
  padding: var(--sm); text-decoration: underline;
}

/* --- 앱 ----------------------------------------------------------------- */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

header { position: sticky; top: 0; background: var(--panel); z-index: 1; }

#tabs {
  display: flex; gap: var(--sm); overflow-x: auto;
  padding: var(--md) var(--md) var(--sm);
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--sm) var(--lg); min-height: 40px;
  color: var(--muted); white-space: nowrap;
  transition: background 200ms, color 200ms, border-color 200ms;
}
.tab.active { color: var(--text); border-color: var(--accent); background: var(--surface-hover); }

.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sm); padding: 0 var(--lg) var(--sm);
  color: var(--muted); font-size: 12px;
}
.bar button {
  background: none; border: none; color: var(--muted);
  text-decoration: underline; padding: var(--xs);
}

main { flex: 1; display: flex; padding: 0 var(--md); min-height: 0; }

#memoView { flex: 1; display: flex; flex-direction: column; min-height: 0; }

#memo {
  flex: 1; width: 100%; background: transparent; border: none; resize: none;
  padding: var(--sm); line-height: 1.7;
}
#memo:focus { outline: none; }

/* --- 밀려난 본문 --------------------------------------------------------- */
#conflictToggle {
  align-self: flex-start; background: none; border: none;
  color: var(--warning); font-size: 12px; text-decoration: underline;
  padding: var(--sm) var(--xs); min-height: 40px;
}

#conflicts {
  list-style: none; margin: 0; padding: 0 0 var(--sm);
  max-height: 45dvh; overflow-y: auto;
}
#conflicts li {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--sm); padding: var(--sm); margin-bottom: var(--sm);
}
.conflict-when { display: block; color: var(--muted); font-size: 11px; }
.conflict-body {
  margin: var(--xs) 0; max-height: 8em; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word; font-size: 13px;
}
#conflicts button {
  background: var(--surface-hover); border: 1px solid var(--border);
  border-radius: var(--sm); color: var(--text);
  padding: var(--xs) var(--md); min-height: 36px; font-size: 12px;
}

/* --- 달력 --------------------------------------------------------------- */
#calendarView { flex: 1; display: flex; flex-direction: column; min-height: 0; }

#calHead {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--xs) 0 var(--sm);
}
#calHead button {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--sm); color: var(--text);
  width: 40px; min-height: 40px; font-size: 18px;
}
#calTitle { font-weight: 600; }

#calGrid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
}
.wday {
  text-align: center; color: var(--muted); font-size: 11px;
  padding-bottom: var(--xs);
}
.day {
  background: none; border: 1px solid transparent; border-radius: var(--sm);
  color: var(--text); aspect-ratio: 1; font-size: 13px;
  position: relative; padding: 0;
}
.day.blank { visibility: hidden; }
.day.today { border-color: var(--border); font-weight: 700; }
.day.picked { background: var(--surface-hover); border-color: var(--calendar); }
.day.marked::after {
  content: ""; position: absolute; left: 50%; bottom: 5px;
  width: 4px; height: 4px; border-radius: 50%;
  background: currentColor; transform: translateX(-50%);
}

#calDay {
  margin: var(--md) 0 var(--xs); font-size: 13px; font-weight: 600;
}

#calEntries {
  list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1;
}
.cal-entry {
  display: grid; grid-template-columns: 3px auto 1fr; gap: var(--sm);
  align-items: start; padding: var(--sm) 0;
}
.cal-mark { border-radius: 1.5px; height: 16px; }
.cal-clock { font-size: 12px; white-space: nowrap; }
.cal-text { font-size: 14px; word-break: break-word; }
.cal-entry.done .cal-text { color: var(--done); text-decoration: line-through; }
.cal-empty { color: var(--muted); font-size: 13px; padding: var(--sm) 0; }

#todoView { flex: 1; overflow-y: auto; }

/* --- 항목 --------------------------------------------------------------- */
#rows { list-style: none; margin: 0; padding: 0; }

.row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas: "check text due trash" ". meta meta meta";
  align-items: center; gap: var(--sm);
  padding: var(--sm) var(--xs); border-bottom: 1px solid var(--border);
}

.row input[type=checkbox] {
  grid-area: check; width: 22px; height: 22px; margin: 0;
  accent-color: var(--accent);
}

.row .text {
  grid-area: text; background: transparent; border: none;
  padding: var(--sm) 0; min-width: 0;
}
.row .text:focus { outline: none; border-bottom: 1px solid var(--border); }
.row.done .text { color: var(--done); text-decoration: line-through; }

.row .due {
  grid-area: due; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--sm); padding: var(--xs); font-size: 11px;
  color: var(--muted); max-width: 40vw;
}

.row .trash {
  grid-area: trash; background: none; border: none; color: var(--muted);
  font-size: 22px; line-height: 1; padding: var(--xs) var(--sm);
  min-width: 40px; min-height: 40px;
}

.meta { grid-area: meta; font-size: 11px; color: var(--muted); }
.meta[data-severity="soon"] { color: var(--warning); }
.meta[data-severity="overdue"] { color: var(--danger); }
.row.done .meta { color: var(--done); }

/* --- 추가 --------------------------------------------------------------- */
#addForm {
  display: flex; gap: var(--sm);
  padding: var(--sm) var(--lg) var(--xs);
  position: sticky; bottom: 0; background: var(--panel);
}
#addForm input {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--sm); padding: var(--sm) var(--md); min-height: 44px;
}
#addForm input:focus { outline: none; border-color: var(--accent); }
#addForm button {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--sm); width: 44px; min-height: 44px; font-size: 20px;
}

.account {
  margin: 0; padding: 0 var(--lg) var(--md);
  color: var(--done); font-size: 11px;
}
