* { box-sizing: border-box; }

/* No-JS: hide app and theme toggle so only <noscript> message is visible */
.no-js #app,
.no-js .theme-toggle {
  display: none !important;
}

.noscript-message {
  max-width: 32rem;
  margin: 2rem auto;
  padding: 1.5rem 2rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.noscript-message h1 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

.noscript-message p {
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

.noscript-message p:last-child {
  margin-bottom: 0;
}

:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  --font-serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --bg: #fff;
  --text: #202124;
  --text-muted: #5f6368;
  --border: #dadce0;
  --border-strong: #dadce0;
  --link: #1a73e8;
  --link-hover: #1557b0;
  --input-bg: #fff;
  --error: #c5221f;
  --success: #137333;
  --card-bg: #f8f9fa;
  --card-bg-hover: #e8eaed;
  --blob-bg: #f1f3f4;
  --danger-bg: #c5221f;
  --danger-hover: #a50e0e;
  --primary: #1a73e8;
  --primary-light: rgba(26, 115, 232, 0.12);
  --sidebar-bg: #f8f9fa;
  --row-hover-bg: #e8f0fe;
  --focus: var(--primary);
  --text-scale: 1;
}

html[data-text-size="small"] {
  --text-scale: 0.9;
}
html[data-text-size="default"] {
  --text-scale: 1;
}
html[data-text-size="large"] {
  --text-scale: 1.1;
}
html[data-text-size="xlarge"] {
  --text-scale: 1.25;
}

html {
  font-family: var(--font-mono);
  font-size: calc(100% * var(--text-scale));
  scrollbar-gutter: stable;
  overflow-y: scroll;
}

[data-font="sans"] {
  font-family: var(--font-sans);
}

[data-font="serif"] {
  font-family: var(--font-serif);
  line-height: 1.55;
}

[data-font="mono"] {
  font-family: var(--font-mono);
}

/* Override body’s .font-sans so the user’s choice (on html) actually applies */
html[data-font="sans"] body,
html[data-font="serif"] body,
html[data-font="mono"] body {
  font-family: inherit;
}
html[data-font="serif"] body {
  line-height: 1.55;
}

/* When user chooses sans/serif, nav, main area, and footer must not stay Courier (style.css sets these in places) */
html[data-font="sans"] .plaintext-nav,
html[data-font="serif"] .plaintext-nav,
html[data-font="sans"] .plaintext-contacts,
html[data-font="serif"] .plaintext-contacts {
  font-family: inherit;
}
/* App name ":: salted harbor ::" always system monospace in nav and footer */
.plaintext-nav .plaintext-nav-logo,
#footer .app-name-mono {
  font-family: var(--font-mono);
}
html[data-font="sans"] .plaintext-contacts .pt-search,
html[data-font="serif"] .plaintext-contacts .pt-search,
html[data-font="sans"] .plaintext-contacts .pt-file-input-wrap,
html[data-font="serif"] .plaintext-contacts .pt-file-input-wrap {
  font-family: inherit;
}
html[data-font="sans"] #footer,
html[data-font="serif"] #footer {
  font-family: inherit;
}

/* Override all px font-sizes so text scales with root (text size preference). 10px=0.625rem, 11px=0.6875rem, 12px=0.75rem, 13px=0.8125rem */
.text-\[10px\] {
  font-size: 0.625rem;
}
.text-\[11px\] {
  font-size: 0.6875rem;
}
.plaintext-nav,
.plaintext-contacts,
.plaintext-contacts .pt-table,
.plaintext-contacts .pt-search,
.plaintext-contacts-empty,
.plaintext-calendar [data-calendar-header-slot] header h1,
.plaintext-calendar [data-calendar-header-slot] header time,
.plaintext-calendar .pt-cal-ascii {
  font-size: 0.8125rem;
}
.plaintext-calendar .pt-cal-month-table .pt-cal-day-events li.pt-cal-event {
  font-size: 0.75rem;
}
/* Contacts pagination: match table/contacts font size (style.css uses 0.9375rem for rows) */
.plaintext-contacts-pagination,
.plaintext-contacts-pagination-rows,
.plaintext-contacts-pagination-indicator,
.plaintext-contacts-pagination-page-trigger,
.plaintext-contacts-pagination-prev,
.plaintext-contacts-pagination-next {
  font-size: 0.8125rem;
}

/* Contacts table checkboxes: nudge down so row text is vertically centered in the checkbox */
.plaintext-contacts .pt-table .pt-table-th-check .pt-table-check,
.plaintext-contacts .pt-table .pt-table-td-check .pt-table-check {
  vertical-align: middle;
  margin-top: 0.15em;
}

/* Copy button: shown on hover for email/phone cells, inline after text */
.plaintext-contacts .pt-col-email .pt-cell-inner,
.plaintext-contacts .pt-col-phone .pt-cell-inner {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  overflow: hidden;
}
.plaintext-contacts .pt-col-email .pt-cell-value,
.plaintext-contacts .pt-col-phone .pt-cell-value {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.2;
}
.plaintext-contacts .pt-col-email .pt-copy-hover,
.plaintext-contacts .pt-col-phone .pt-copy-hover {
  flex-shrink: 0;
  opacity: 0;
  display: inline-flex;
  align-items: center;
  align-self: center;
  transition: opacity 0.15s ease;
  line-height: 1;
}
.plaintext-contacts .pt-col-email:hover .pt-copy-hover,
.plaintext-contacts .pt-col-phone:hover .pt-copy-hover {
  opacity: 1;
}
.plaintext-contacts .pt-copy-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  line-height: 0;
  margin-top: -0.15em;
}
.plaintext-contacts .pt-copy-btn svg {
  display: block;
  vertical-align: middle;
}
.plaintext-contacts .pt-copy-btn:hover {
  color: var(--link);
}

/* Copy tooltip: helper text shown on click, not in cell */
.pt-copy-tooltip {
  position: fixed;
  z-index: 9999;
  font-size: 0.75rem;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transition: opacity 0.1s ease;
  pointer-events: none;
  white-space: nowrap;
}
.pt-copy-tooltip.pt-copy-tooltip-visible {
  opacity: 1;
}

/* Calendar: day-of-week labels must stay on one line (no wrap), table can resize */
.plaintext-calendar .pt-cal-month-table {
  font-size: 0.8125rem;
  min-width: 1px;
  table-layout: fixed;
}
.plaintext-calendar .pt-cal-month-table th {
  font-size: 0.75rem;
  white-space: nowrap;
  min-width: 2.25rem;
}
/* Template month view (grid with Mon, Tue, …) */
.plaintext-calendar div.overflow-auto > div.grid.grid-cols-7:first-child > div {
  white-space: nowrap;
}
/* JS-built month grid (pt-cal-tailwind) day header cells */
.plaintext-calendar .pt-cal-tailwind .grid > div.break-words {
  white-space: nowrap;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1a1a;
    --text: #e5e5e5;
    --text-muted: #a0a0a0;
    --border: #333;
    --border-strong: #444;
    --link: #6eb3f7;
    --link-hover: #8ec8ff;
    --input-bg: #2a2a2a;
    --error: #f66;
    --success: #6c6;
    --card-bg: #252525;
    --card-bg-hover: #2e2e2e;
    --blob-bg: #222;
    --danger-bg: #c44;
    --danger-hover: #e55;
    --row-hover-bg: rgba(138, 180, 248, 0.12);
  }
}

[data-theme="dark"] {
  --bg: #202124;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --border: #3c4043;
  --border-strong: #5f6368;
  --link: #8ab4f8;
  --link-hover: #aecbfa;
  --input-bg: #303134;
  --error: #f28b82;
  --success: #81c995;
  --card-bg: #292a2d;
  --card-bg-hover: #35363a;
  --blob-bg: #292a2d;
  --danger-bg: #ea4335;
  --danger-hover: #f28b82;
  --primary: #8ab4f8;
  --primary-light: rgba(138, 180, 248, 0.15);
  --sidebar-bg: #292a2d;
  --row-hover-bg: rgba(138, 180, 248, 0.12);
  --focus: var(--primary);
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  scrollbar-gutter: stable;
}

/* Full-screen overlays (import dialogs, password change) – theme-aware for dark mode */
.pt-import-overlay,
.pt-password-change-overlay {
  background: color-mix(in srgb, var(--bg, #fff) 92%, transparent);
}

h1 { margin-top: 0; }

.error { color: var(--error); }
.error.hidden { display: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--text-muted); font-size: 0.9em; }
.muted.hidden { display: none; }

.unlock-hint { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }

label { display: block; margin-bottom: 0.5rem; }

@layer base {
  input {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
  }

  button {
    padding: 0.5rem 1rem;
    margin-right: 0.5rem;
    margin-top: 0.5rem;
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    cursor: pointer;
  }

  button:hover { background: var(--card-bg-hover); }
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
