/* ── Reset & base ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; min-height: 100vh; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; }

/* ── Themes ─────────────────────────────────────── */
:root {
  --bg: #1a1825;
  --bg2: rgba(255,255,255,0.06);
  --bg3: rgba(255,255,255,0.03);
  --border: rgba(255,255,255,0.10);
  --border2: rgba(255,255,255,0.18);
  --text: #e4e2f0;
  --text2: rgba(228,226,240,0.55);
  --text3: rgba(228,226,240,0.35);
  --accent: #7c6af7;
  --accent-light: rgba(124,106,247,0.18);
  --accent-text: #a89df8;
  --success: #5dcaa5;
  --success-light: rgba(93,202,165,0.18);
  --danger: #f07575;
  --shadow: rgba(0,0,0,0.35);
  --pomo-track: rgba(255,255,255,0.08);
  --radius: 12px;
  --widget-pad: 16px 18px;
}
body.theme-dusk { --bg:#1a1825; --accent:#7c6af7; --accent-light:rgba(124,106,247,0.18); --accent-text:#a89df8; }
body.theme-midnight { --bg:#0d0d14; --bg2:rgba(255,255,255,0.05); --accent:#4f8ef7; --accent-light:rgba(79,142,247,0.18); --accent-text:#82b0f8; }
body.theme-forest { --bg:#0f1a14; --bg2:rgba(255,255,255,0.06); --accent:#3da87a; --accent-light:rgba(61,168,122,0.18); --accent-text:#6dcba5; }
body.theme-slate { --bg:#16202c; --bg2:rgba(255,255,255,0.06); --accent:#5b8fa8; --accent-light:rgba(91,143,168,0.18); --accent-text:#8db8cc; }
body.theme-rose { --bg:#1e1218; --bg2:rgba(255,255,255,0.06); --accent:#c46b8f; --accent-light:rgba(196,107,143,0.18); --accent-text:#de9ab7; }
body.theme-light {
  --bg:#f0eff5; --bg2:rgba(0,0,0,0.04); --bg3:rgba(0,0,0,0.02);
  --border:rgba(0,0,0,0.10); --border2:rgba(0,0,0,0.18);
  --text:#1a1825; --text2:rgba(26,24,37,0.55); --text3:rgba(26,24,37,0.35);
  --accent:#6254d4; --accent-light:rgba(98,84,212,0.12); --accent-text:#6254d4;
  --success:#2a9b71; --success-light:rgba(42,155,113,0.12);
  --danger:#c94040; --shadow:rgba(0,0,0,0.12); --pomo-track:rgba(0,0,0,0.08);
}

/* ── Background image support ───────────────────── */
body.has-bg-image {
  background-size: cover !important;
  background-position: center !important;
  background-attachment: fixed !important;
}
body.has-bg-image .widget {
  background: rgba(0,0,0,0.45) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-color: rgba(255,255,255,0.12) !important;
}
body.has-bg-image.theme-light .widget {
  background: rgba(255,255,255,0.5) !important;
  border-color: rgba(255,255,255,0.4) !important;
}
body.has-bg-image .dash-header { text-shadow: 0 1px 6px rgba(0,0,0,0.5); }
body.has-bg-image.theme-light .dash-header { text-shadow: 0 1px 4px rgba(0,0,0,0.2); }

/* ── Page body ──────────────────────────────────── */
body {
  background-color: var(--bg);
  color: var(--text);
  transition: background 0.3s;
}

/* ── Settings gear ──────────────────────────────── */
.gear-btn {
  position: fixed; top: 18px; right: 18px; z-index: 200;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 50%; width: 36px; height: 36px;
  font-size: 16px; cursor: pointer; color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.gear-btn:hover { background: var(--bg3); color: var(--text); }

/* ── Settings panel ─────────────────────────────── */
.settings-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 300;
  width: 320px; background: var(--bg);
  border-left: 1px solid var(--border2);
  overflow-y: auto;
  transition: transform 0.25s ease;
  box-shadow: -4px 0 32px var(--shadow);
}
.settings-panel.hidden { transform: translateX(100%); }
.settings-inner { padding: 20px; }
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 600; margin-bottom: 24px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text3); margin-bottom: 10px; font-weight: 500; }
.settings-hint { font-size: 11px; color: var(--text3); margin-bottom: 8px; line-height: 1.5; }

/* Theme swatches */
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme-swatch {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 4px; cursor: pointer;
  font-size: 11px; color: var(--text2); transition: border-color 0.15s;
}
.theme-swatch:hover, .theme-swatch.active { border-color: var(--accent); color: var(--text); }
.swatch-preview { display: block; width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.1); }
.s-dusk    { background: radial-gradient(circle at 40% 40%, #7c6af7, #1a1825); }
.s-midnight{ background: radial-gradient(circle at 40% 40%, #4f8ef7, #0d0d14); }
.s-forest  { background: radial-gradient(circle at 40% 40%, #3da87a, #0f1a14); }
.s-slate   { background: radial-gradient(circle at 40% 40%, #5b8fa8, #16202c); }
.s-rose    { background: radial-gradient(circle at 40% 40%, #c46b8f, #1e1218); }
.s-light   { background: radial-gradient(circle at 40% 40%, #6254d4, #f0eff5); }

/* BG image */
.bg-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn {
  display: inline-block; padding: 6px 12px;
  background: var(--accent-light); border: 1px solid var(--accent);
  border-radius: 6px; font-size: 12px; color: var(--accent-text);
  cursor: pointer; transition: background 0.15s;
}
.file-btn:hover { background: rgba(124,106,247,0.28); }
#bg-preview-wrap { margin-top: 8px; }
#bg-preview { width: 100%; border-radius: 6px; border: 1px solid var(--border); max-height: 120px; object-fit: cover; }

/* Pomo settings */
.pomo-settings-row { display: flex; gap: 10px; flex-wrap: wrap; }
.pomo-settings-row label { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 5px; }
.pomo-settings-row input[type=number] { width: 48px; }

/* Habit settings */
#habit-settings-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.habit-setting-row { display: flex; align-items: center; justify-content: space-between; background: var(--bg2); border-radius: 6px; padding: 6px 10px; font-size: 12px; }
.habit-add-row { display: flex; gap: 8px; }

/* Form elements */
input[type=text], input[type=number], input[type=time], textarea {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; color: var(--text);
  font-size: 13px; font-family: inherit; outline: none;
  transition: border-color 0.15s;
}
input[type=text]:focus, input[type=number]:focus, input[type=time]:focus, textarea:focus { border-color: var(--accent); }
input[type=text]::placeholder, textarea::placeholder { color: var(--text3); }

/* Buttons */
.ghost-btn {
  background: transparent; border: 1px solid var(--border2);
  border-radius: 6px; padding: 6px 12px; color: var(--text2);
  font-size: 12px; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.ghost-btn:hover { background: var(--bg2); color: var(--text); }
.icon-btn { background: none; border: none; cursor: pointer; color: var(--text2); font-size: 15px; padding: 2px 6px; }
.icon-btn:hover { color: var(--text); }
.icon-add-btn {
  background: var(--accent-light); border: 1px solid var(--accent);
  border-radius: 6px; color: var(--accent-text); font-size: 18px;
  width: 32px; height: 32px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  line-height: 1; transition: background 0.15s;
}
.icon-add-btn:hover { background: rgba(124,106,247,0.28); }
.tiny-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 8px; font-size: 11px;
  color: var(--text3); cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.tiny-btn:hover { color: var(--text2); border-color: var(--border2); }

/* ── Dashboard layout ───────────────────────────── */
.dashboard {
  max-width: 1280px; margin: 0 auto;
  padding: 32px 28px 40px;
  min-height: 100vh; display: flex; flex-direction: column; gap: 20px;
}

/* Header */
.dash-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 8px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: baseline; gap: 14px; }
.clock { font-size: 36px; font-weight: 300; letter-spacing: -0.5px; color: var(--text); font-variant-numeric: tabular-nums; }
.date-str { font-size: 13px; color: var(--text2); }
.greeting { font-size: 16px; color: var(--text2); }

/* Widget grid */
.widget-grid {
  display: grid;
  grid-template-columns: 200px 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 14px;
}

/* ── Widgets ────────────────────────────────────── */
.widget {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--widget-pad);
  display: flex; flex-direction: column; gap: 10px;
}
.widget-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--text3); font-weight: 500;
}
.widget-sublabel { font-size: 10px; text-transform: none; letter-spacing: 0; color: var(--text3); }
.widget-label-row { display: flex; align-items: center; justify-content: space-between; }

/* Pomodoro */
.widget-pomo { grid-column: 1; grid-row: 1; align-items: center; }
.pomo-ring-wrap { position: relative; width: 110px; height: 110px; }
.pomo-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.pomo-track { fill: none; stroke: var(--pomo-track); stroke-width: 7; }
.pomo-progress { fill: none; stroke: var(--accent); stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.pomo-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.pomo-time { font-size: 22px; font-weight: 400; font-variant-numeric: tabular-nums; color: var(--text); }
.pomo-mode-label { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.07em; margin-top: 2px; }
.pomo-session-info { font-size: 11px; color: var(--text3); }
.pomo-btns { display: flex; gap: 8px; width: 100%; }
.pomo-btn {
  flex: 1; padding: 7px 0; border-radius: 6px; font-size: 12px;
  cursor: pointer; background: var(--accent-light); border: 1px solid var(--accent);
  color: var(--accent-text); transition: background 0.15s;
}
.pomo-btn:hover { background: rgba(124,106,247,0.28); }
.pomo-btn-ghost { background: transparent; border-color: var(--border2); color: var(--text3); }
.pomo-btn-ghost:hover { background: var(--bg2); color: var(--text2); }
.pomo-btn.running { background: var(--accent); color: #fff; border-color: var(--accent); }

/* To-do */
.widget-todo { grid-column: 2; grid-row: 1 / 3; }
.todo-actions { display: flex; gap: 6px; position: relative; }
.todo-list {
  list-style: none; display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto; max-height: 280px; flex: 1;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.todo-item {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 4px; border-radius: 6px;
  border-bottom: 1px solid var(--border); transition: background 0.1s;
}
.todo-item:hover { background: var(--bg2); }
.todo-item:last-child { border-bottom: none; }
.todo-check {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid var(--border2); flex-shrink: 0;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.todo-check.checked { background: var(--accent); border-color: var(--accent); }
.todo-check.checked::after {
  content: ''; display: block;
  width: 5px; height: 3px;
  border-left: 1.5px solid #fff; border-bottom: 1.5px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}
.todo-text { flex: 1; font-size: 13px; color: var(--text); line-height: 1.4; cursor: text; }
.todo-text.done { color: var(--text3); text-decoration: line-through; }
.todo-del {
  opacity: 0; background: none; border: none; color: var(--danger);
  cursor: pointer; font-size: 15px; padding: 0 2px; transition: opacity 0.15s;
}
.todo-item:hover .todo-del { opacity: 1; }
.todo-add-row { display: flex; gap: 6px; }
.todo-add-row input { flex: 1; }
.todo-footer { display: flex; align-items: center; justify-content: space-between; }
.todo-count { font-size: 11px; color: var(--text3); }
.export-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 50;
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: 8px; overflow: hidden; white-space: nowrap;
  box-shadow: 0 4px 16px var(--shadow);
}
.export-menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 14px; background: none; border: none;
  font-size: 12px; color: var(--text2); cursor: pointer;
}
.export-menu button:hover { background: var(--bg2); color: var(--text); }

/* Notepad */
.widget-notepad { grid-column: 3; grid-row: 1 / 3; }
.widget-notepad textarea {
  flex: 1; width: 100%; resize: none; min-height: 340px;
  border: none; background: transparent; padding: 0;
  font-size: 13px; line-height: 1.65; color: var(--text);
}
.widget-notepad textarea:focus { outline: none; }

/* Habits */
.widget-habits { grid-column: 1; grid-row: 2; }
.habit-list { display: flex; flex-direction: column; gap: 8px; }
.habit-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.habit-name { font-size: 12px; color: var(--text2); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-dots { display: flex; gap: 4px; }
.habit-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--pomo-track); cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  border: none; padding: 0;
}
.habit-dot:hover { transform: scale(1.3); }
.habit-dot.done { background: var(--success); }
.habit-dot.today { box-shadow: 0 0 0 2px var(--accent); }
.habit-empty { font-size: 12px; color: var(--text3); text-align: center; padding: 12px 0; }

/* Day planner */
.widget-planner { grid-column: 2 / 3; grid-row: 3; }
.planner-view-toggle { display: flex; gap: 4px; }
.view-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 8px; font-size: 11px;
  color: var(--text3); cursor: pointer; transition: all 0.15s;
}
.view-btn.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent-text); }

/* Blocks view */
.blocks-list { display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; scrollbar-width: thin; }
.time-block-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg3); border-radius: 6px; padding: 6px 10px;
  border-left: 3px solid var(--accent);
}
.block-time-range { font-size: 11px; color: var(--text3); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 80px; }
.block-item-label { flex: 1; font-size: 13px; color: var(--text); }
.block-del { opacity: 0; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; padding: 0 2px; transition: opacity 0.15s; }
.time-block-item:hover .block-del { opacity: 1; }
.block-add-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.block-add-row .time-input { width: 90px; }
.block-dash { color: var(--text3); font-size: 12px; }
.block-label-input { flex: 1; min-width: 100px; }

/* List view */
.planner-list { list-style: none; display: flex; flex-direction: column; gap: 3px; max-height: 220px; overflow-y: auto; scrollbar-width: thin; }
.plan-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 4px; border-bottom: 1px solid var(--border);
}
.plan-item:last-child { border-bottom: none; }
.plan-item-time { font-size: 11px; color: var(--accent-text); font-variant-numeric: tabular-nums; min-width: 38px; }
.plan-item-text { flex: 1; font-size: 13px; color: var(--text); }
.plan-del { opacity: 0; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; padding: 0 2px; transition: opacity 0.15s; }
.plan-item:hover .plan-del { opacity: 1; }
.plan-add-row { display: flex; gap: 6px; align-items: center; }
.plan-add-row input[type=text] { flex: 1; }
.plan-time-opt { width: 90px; }

/* ── Utilities ───────────────────────────────────── */
.hidden { display: none !important; }

/* Responsive tweak for narrow screens */
@media (max-width: 860px) {
  .widget-grid { grid-template-columns: 1fr 1fr; }
  .widget-todo { grid-column: 1 / 3; grid-row: auto; }
  .widget-notepad { grid-column: 1 / 3; grid-row: auto; }
  .widget-habits { grid-column: 1; grid-row: auto; }
  .widget-planner { grid-column: 1 / 3; grid-row: auto; }
}
@media (max-width: 540px) {
  .widget-grid { grid-template-columns: 1fr; }
  .widget-todo, .widget-notepad, .widget-habits, .widget-planner { grid-column: 1; }
}
