/* ==========================================================================
   FOLIO — component library
   Buttons, cards, inputs, tasks, progress, dialogs, ornaments…
   Everything a widget needs, in one shared stylesheet.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Page shell
   -------------------------------------------------------------------------- */
.widget {
  position: relative;
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 50% -8%, var(--gold-soft), transparent 65%),
    radial-gradient(rgba(80, 60, 25, 0.045) 1px, transparent 1.4px);
  background-size: auto, 26px 26px;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 22px 44px;
}

.widget--bare .app { max-width: none; padding: 0; }

/* --- header chrome --- */
.app-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.app-head-main { display: flex; align-items: flex-start; gap: 0; }

.bookmark {
  flex: none;
  width: 13px;
  height: 34px;
  margin: -4px 11px 0 0;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 74%, 0 100%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
}

.app-title {
  font-size: clamp(19px, 2.6vw, 24px);
  margin: 0;
  letter-spacing: 0.01em;
}

.app-desc { margin: 3px 0 0; font-size: 13px; color: var(--ink-500); }

.app-head-actions { display: flex; gap: 4px; margin-top: 2px; }

.widget-body { animation: fadeIn 0.4s ease both; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  background: var(--paper-1);
  color: var(--ink-700);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.05s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); color: var(--accent-ink); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-500); }
.btn-ghost:hover { background: var(--paper-2); color: var(--ink-900); }

.btn-lg { padding: 11px 24px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.btn-icon {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-500);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.btn-icon:hover { background: var(--paper-2); color: var(--ink-900); text-decoration: none; }
.btn-icon svg { display: block; }

.btn:disabled { opacity: 0.45; cursor: default; pointer-events: none; }

/* --------------------------------------------------------------------------
   Cards, wells, badges
   -------------------------------------------------------------------------- */
.card {
  background: var(--paper-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px;
}
.card + .card { margin-top: 12px; }
.card--pad-sm { padding: 12px 14px; }
.card--accent { border-left: 3px solid var(--accent); }

.well {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.badge, .chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-500);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 10px;
}
.badge--accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.badge--gold { color: var(--gold); background: var(--gold-soft); border-color: transparent; }
.badge--forest { color: var(--forest); background: var(--forest-soft); border-color: transparent; }
.badge--danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

/* --------------------------------------------------------------------------
   Inputs
   -------------------------------------------------------------------------- */
.input, .select, .textarea {
  font: inherit;
  font-size: 14px;
  color: var(--ink-700);
  background: var(--paper-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--ink-300); }

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8172' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 32px;
  cursor: pointer;
}

/* custom checkbox (tasks) */
.check {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  flex: none;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: var(--paper-1);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
  margin: 0;
}
.check:hover { border-color: var(--accent); }
.check:checked { background: var(--accent); border-color: var(--accent); }
.check:checked::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid var(--accent-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* toggle switch */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 38px;
  height: 22px;
  flex: none;
  border-radius: 99px;
  background: var(--line-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  margin: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }
.switch:focus-visible { box-shadow: var(--focus-ring); }

/* range */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--paper-1);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--paper-1);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
input[type="range"]:focus-visible { box-shadow: var(--focus-ring); }

input[type="color"] {
  width: 44px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper-1);
  cursor: pointer;
}

/* segmented control */
.seg {
  display: inline-flex;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--ink-500);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn:hover { color: var(--ink-900); }
.seg-btn[aria-checked="true"], .seg-btn.is-active {
  background: var(--paper-1);
  color: var(--ink-900);
  box-shadow: 0 1px 3px rgba(60, 45, 20, 0.16);
}

/* --------------------------------------------------------------------------
   Task lists
   -------------------------------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }

.task {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.task:hover { background: var(--paper-2); }
.task.done .task-text { text-decoration: line-through; color: var(--ink-300); }
.task-text { flex: 1; font-size: 14.5px; word-break: break-word; }
.task-text .task-sub { display: block; font-size: 12px; color: var(--ink-300); margin-top: 1px; }
.task-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
.task:hover .task-actions { opacity: 1; }
@media (hover: none) { .task-actions { opacity: 1; } }

/* --------------------------------------------------------------------------
   Progress
   -------------------------------------------------------------------------- */
.progress {
  height: 8px;
  border-radius: 99px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.45s ease;
}

.ring { position: relative; display: inline-grid; place-items: center; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-bg { stroke: var(--paper-2); }
.ring .ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.5s ease; }
.ring-label { position: absolute; font-weight: 700; color: var(--ink-900); }

/* --------------------------------------------------------------------------
   Ornaments & misc
   -------------------------------------------------------------------------- */
.ornament { display: flex; align-items: center; gap: 10px; color: var(--gold); }
.ornament::before, .ornament::after {
  content: "";
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}

.rule { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.empty { text-align: center; color: var(--ink-300); padding: 28px 12px; font-size: 14px; }

.muted { color: var(--ink-500); }
.tiny { font-size: 12px; }
.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.serif { font-family: var(--font-serif); }
.big-number { font-family: var(--font-serif); font-weight: 600; color: var(--ink-900); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }

.flex { display: flex; }
.flex-1 { flex: 1; min-width: 0; }
.col { flex-direction: column; }
.wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.spacer { flex: 1; }
.center { text-align: center; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

.fade-in { animation: fadeIn 0.4s ease both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* pulse (status dots) */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.pulse { animation: pulse 1.8s ease-in-out infinite; }

/* --------------------------------------------------------------------------
   Settings dialog
   -------------------------------------------------------------------------- */
.settings-dialog {
  border: none;
  background: var(--paper-1);
  color: var(--ink-700);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  padding: 0;
  width: min(460px, calc(100vw - 32px));
  max-height: min(84vh, 680px);
}
.settings-dialog::backdrop { background: rgba(26, 20, 10, 0.45); backdrop-filter: blur(2px); }
.settings-dialog[open] { animation: dlgIn 0.18s ease both; }
@keyframes dlgIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.dialog-title { font-size: 17px; margin: 0; }

.dialog-body { padding: 16px 18px; overflow-y: auto; max-height: 58vh; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

.dlg-sec + .dlg-sec { margin-top: 20px; }
.dlg-sec-title {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-300);
  margin: 0 0 10px;
}
.dlg-fields { display: grid; gap: 13px; }

.field { display: grid; gap: 5px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-500); }
.field--wide { grid-column: 1 / -1; }

.dlg-hint { font-size: 12px; color: var(--ink-300); margin: 8px 0 0; }

.number-field { display: flex; align-items: center; gap: 7px; }
.number-field .input { width: 96px; flex: none; }
.number-field .suffix { color: var(--ink-300); font-size: 13px; }

.range-row { display: flex; align-items: center; gap: 10px; }
.range-row .input { flex: 1; }
.range-out { font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; font-weight: 600; color: var(--ink-900); }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 420px) {
  .app { padding: 18px 14px 36px; }
  .card { padding: 14px; }
  .btn-lg { padding: 10px 18px; }
}
