/* Shared elements: typography, buttons, cards, chips, form controls, toast. */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font-body); background: var(--ground); color: var(--ink);
  -webkit-font-smoothing: antialiased; }
a { color: var(--violet-link); text-decoration: none; }
a:hover { color: var(--violet-deep); }
button { font-family: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
h1, h2, h3, p { margin: 0; }
svg { flex-shrink: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid rgba(116, 86, 246, .45); outline-offset: 2px; }
.num { font-family: var(--font-num); }
.muted { color: var(--muted); }
.grow { flex-grow: 1; }

/* Page frame */
.page { box-sizing: border-box; min-height: 100%; padding: 40px 48px; display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.page-titles { display: flex; flex-direction: column; gap: 6px; }
.page-titles h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.8px; }
.page-titles p { font-size: 16px; color: var(--muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px;
  border-radius: var(--radius); border: 1px solid transparent; font-size: 15px; font-weight: 600; white-space: nowrap;
  background: transparent; color: var(--ink); }
.btn-primary { background: var(--violet); color: #FFFFFF; font-weight: 700; }
.btn-primary:hover:not(:disabled) { background: var(--violet-hover); color: #FFFFFF; }
.btn-dark { background: var(--ink); color: #FFFFFF; }
.btn-outline { background: var(--surface); border-color: var(--line-3); color: var(--ink); }
.btn-outline:hover:not(:disabled) { border-color: var(--violet); color: var(--ink); }
.btn-soft { background: var(--violet-soft); color: var(--violet-strong); font-weight: 700; }
.btn-danger-outline { background: var(--surface); border-color: var(--danger-line); color: var(--danger); }
.btn-link { height: auto; padding: 0; align-self: flex-start; color: var(--violet-strong); font-size: 14px; }
.btn-lg { height: 52px; padding: 0 22px; border-radius: var(--radius-md); font-size: 16px; }
.btn-sm { height: 40px; padding: 0 14px; border-radius: var(--radius-sm); font-size: 14px; }
.btn-xs { height: 32px; padding: 0 12px; border-radius: 999px; font-size: 13px; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 8px; color: var(--muted); }
.btn-icon:hover { background: var(--violet-softer); }
.btn[aria-busy="true"] { opacity: .7; pointer-events: none; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-xl); }
.card-focus { border: 2px solid var(--violet); box-shadow: var(--shadow-focus); }

/* Headings with counters */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.section-head h2 { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; }
.count { font-family: var(--font-num); font-size: 13px; font-weight: 600; min-width: 24px; height: 24px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; background: var(--violet-soft); color: var(--violet-strong); }
.count-grey { font-size: 12px; min-width: 0; height: auto; padding: 1px 8px; background: var(--tab-track); color: var(--text-2); }
.link-more { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--muted); background: none; border: 0; padding: 0; }
.link-more:hover { color: var(--violet-strong); }

/* Chips and badges */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.chip-done { background: var(--lime-soft); color: var(--lime-ink); }
.chip-todo { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
.chip-violet { background: var(--violet-soft); color: var(--violet-strong); font-size: 14px; padding: 6px 12px; }
.chip-danger { background: var(--danger-soft); color: var(--danger); font-weight: 700; padding: 5px 10px; }
.chip-lime { background: var(--lime); color: var(--ink); font-size: 12px; font-weight: 700; padding: 3px 9px; gap: 4px; }
.badge-lime { padding: 2px 8px; border-radius: 999px; background: var(--lime); color: var(--ink); font-size: 12px; font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ok); flex-shrink: 0; }
.dot-danger { width: 7px; height: 7px; background: var(--danger-dot); }

/* Form controls */
.field-grid { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px 20px; align-items: start; }
.field-label { padding-top: 12px; font-size: 14px; font-weight: 700; }
.input, .select, .textarea { width: 100%; height: 44px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line-3);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; }
.textarea { height: 104px; padding: 12px 14px; font-size: 14px; line-height: 1.6; resize: none; }
.select { appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235A5C73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(116, 86, 246, .15); }
.field-hint { margin-top: 6px; font-size: 13px; color: var(--muted-2); }
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--violet); flex-shrink: 0; }
input[type="range"] { accent-color: var(--violet); }

.check-list { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: var(--radius-md); background: var(--ground); }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 38px; font-size: 14px; }

/* Switch (role="switch" button) */
.switch { width: 48px; height: 28px; flex-shrink: 0; padding: 3px; display: flex; justify-content: flex-start;
  border: none; border-radius: 999px; background: var(--switch-off); transition: background .15s; }
.switch::after { content: ""; width: 22px; height: 22px; border-radius: 50%; background: #FFFFFF; }
.switch[aria-checked="true"] { justify-content: flex-end; background: var(--violet); }

.setting-row { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.setting-row:last-child { border-bottom: 0; }
.setting-text { flex-grow: 1; display: flex; flex-direction: column; gap: 2px; }
.setting-title { font-size: 15px; font-weight: 600; }
.setting-desc { font-size: 13px; color: var(--muted-2); }

/* Segmented control */
.segmented { display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; gap: 4px; padding: 4px; border-radius: var(--radius); background: var(--surface-2); }
.segmented button { height: 40px; border: none; border-radius: 9px; background: transparent; color: var(--text-2); font-size: 14px; font-weight: 600; }
.segmented button[aria-checked="true"] { background: var(--ink); color: #FFFFFF; font-weight: 700; }

/* Popup menu */
.menu { position: absolute; z-index: 20; min-width: 200px; padding: 6px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: 0 16px 40px rgba(25, 27, 46, .14); }
.menu button { display: flex; width: 100%; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); font-size: 14px; text-align: left; }
.menu button:hover { background: var(--violet-softer); }
.menu .danger { color: var(--danger); }

/* Toast */
.toast-region { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { max-width: 560px; padding: 12px 18px; border-radius: var(--radius); background: var(--ink); color: #FFFFFF; font-size: 14px;
  box-shadow: 0 12px 30px rgba(25, 27, 46, .25); animation: toast-in .18s ease-out; }
.toast-error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Empty and loading states */
.empty { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 24px; border-radius: var(--radius-xl);
  background: var(--surface); border: 1px dashed var(--line-3); color: var(--muted); font-size: 15px; }
.empty strong { color: var(--ink); font-size: 17px; }
.skeleton { border-radius: var(--radius-xl); background: linear-gradient(90deg, #EFEDFB 25%, #F7F6FF 50%, #EFEDFB 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite linear; min-height: 96px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton, .toast { animation: none; } }
