/* The page shell: top bar, menus and popovers, launcher, the three panes, and the shared
   components (buttons, fields, segmented control, settings sheet, confirmation dialog, the
   "changed elsewhere" notice). Measured on iCloud.com. */

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

/* ---- top bar: 44 px, product name, the app's name in its accent colour -------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-4);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-topbar);
}

.topbar-home,
.topbar-app {
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  border-radius: var(--radius-s);
}
.topbar-app { color: var(--accent); margin-left: calc(-1 * var(--space-2)); }
.topbar-spacer { flex: 1; }

/* ---- menus and popovers (details/summary: they work without JavaScript) -------------------- */

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }

.menu-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 32px;
  height: 32px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-s);
}
.menu-button:hover,
.menu[open] > .menu-button { background: var(--bg-hover); }

.menu-list {
  position: absolute;
  z-index: 50;
  top: calc(100% + var(--space-1));
  left: 0;
  min-width: 220px;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  border-radius: var(--radius-l);
  background: var(--bg-raised);
  box-shadow: var(--shadow);
}
.menu-list-end { left: auto; right: 0; }

/* A menu row: ~30 px, 15 px text, a 16 px line icon in the accent colour on the left. */
.menu-item,
.menu-note {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 30px;
  padding: 0 var(--space-3);
  font-size: var(--text-row);
  border-radius: var(--radius-s);
}
.menu-item > .icon { width: 16px; height: 16px; color: var(--accent); }
.menu-item:hover { background: var(--bg-hover); }
.menu-item[aria-current="page"] { background: var(--bg-selected); }
.menu-note { color: var(--text-secondary); white-space: nowrap; }
.menu-heading { padding: var(--space-2) var(--space-3); white-space: nowrap; }
.menu-heading strong { display: block; font-weight: 600; }
.menu-heading span { color: var(--text-secondary); font-size: var(--text-size); }
.menu-separator { height: 1px; margin: var(--space-1) var(--space-3); background: var(--separator); }
/* Destructive items are red and go last. */
.menu-item-danger,
.menu-item-danger > .icon { color: var(--danger); }

.menu-form { display: block; }
.menu-item-button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

/* The apps popover: five tiles in a grid; its button is iCloud's 3x3 dots. */
.dots-grid {
  display: grid;
  grid-template-columns: repeat(3, 4px);
  gap: 3px;
}
.dots-grid > span { width: 4px; height: 4px; border-radius: 50%; background: var(--text-secondary); }

.apps-popover { padding: var(--space-3); min-width: 0; width: 300px; }
.apps-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}
.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) 0;
  font-size: var(--text-size);
  border-radius: var(--radius-m);
}
.app-tile:hover,
.app-tile[aria-current="page"] { background: var(--bg-selected); }
.app-tile-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  color: #fff;
  background: var(--tile-colour, var(--accent));
}
.tile.app-mail, .app-tile.app-mail { --tile-colour: var(--app-mail); }
.tile.app-calendar, .app-tile.app-calendar { --tile-colour: var(--app-calendar); }
.tile.app-contacts, .app-tile.app-contacts { --tile-colour: var(--app-contacts); }
.tile.app-reminders, .app-tile.app-reminders { --tile-colour: var(--app-reminders); }
.tile.app-notes, .app-tile.app-notes { --tile-colour: var(--app-notes); }

/* The account menu's round avatar. */
.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: var(--text-size);
  font-weight: 600;
  color: #fff;
  background: #8e8e93;
}

/* ---- launcher ------------------------------------------------------------------------- */

.launcher {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}
.launcher h1 { font-family: var(--font-display); font-size: var(--text-title); margin-bottom: var(--space-5); }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-5);
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-l);
}
.tile:hover { background: var(--bg-hover); }

.tile-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  color: #fff;
  background: var(--tile-colour, var(--accent));
}
.tile-name { font-size: var(--text-large); }

/* ---- three panes ---------------------------------------------------------------------- */

.panes {
  /* basis auto, not 0%: body and main have no definite height, so a 0% basis falls back to
     the content height and a long list would grow the whole page instead of scrolling */
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) var(--list-width) minmax(0, 1fr);
  height: calc(100vh - var(--topbar-height));
}

.pane { min-width: 0; min-height: 0; overflow: auto; }
.pane-sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-sidebar);
  padding: var(--space-3) var(--space-2);
}
.pane-list { background: var(--bg-content); border-right: 1px solid var(--separator); }
.pane-detail { background: var(--bg-content); }

.sidebar-heading { padding: var(--space-1) var(--space-3) var(--space-2); }
.sidebar-heading h1,
.sidebar-heading h2 { font-family: var(--font-display); font-size: var(--text-title); font-weight: 600; }

/* A sidebar row: 32 px, 15 px text, inset 10 px, 10 px radius; the selected one is a grey fill. */
.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--row-height);
  margin: 0 var(--space-2);
  padding: 0 var(--space-2);
  font-size: var(--text-row);
  border-radius: var(--radius-m);
}
.sidebar-item > .icon { color: var(--accent); }
.sidebar-item:hover { background: var(--bg-hover); }
.sidebar-item[aria-current="true"],
.sidebar-item[aria-current="page"] { background: var(--bg-selected); }
.sidebar-item-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item-count { color: var(--text-secondary); font-size: var(--text-size); }
.sidebar-section-title {
  margin: var(--space-4) var(--space-3) var(--space-1);
  font-size: var(--text-large);
  font-weight: 600;
}

/* The toolbar row above the list and the detail pane: 48 px. */
.pane-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 48px;
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--separator);
}
.search-field {
  flex: 1;
  height: 32px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-m);
  background: var(--bg-search);
}
.list-header { padding: var(--space-3) var(--space-4); }
.list-header h2 { font-family: var(--font-display); font-size: var(--text-title); font-weight: 600; }
.list-header p { color: var(--text-secondary); }

/* A list row: a card inset 15 px with a 10 px radius; open = the accent fill with white text. */
.list-row {
  display: block;
  margin: 0 15px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-m);
}
.list-row:hover { background: var(--bg-hover); }
.list-row[aria-current="true"] { background: var(--select-fill); color: var(--select-text); }
.list-row[aria-current="true"] .secondary { color: inherit; opacity: 0.85; }
.secondary { color: var(--text-secondary); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 60%;
  padding: var(--space-5);
  text-align: center;
  color: var(--text-secondary);
}
.empty-state-icon { width: 48px; height: 48px; stroke-width: 1.5; }
.empty-state h2 { font-size: var(--text-large); font-weight: 600; }

/* Tablet: sidebar and list narrower; the detail pane stays. */
@media (max-width: 1100px) {
  .panes { grid-template-columns: min(var(--sidebar-width), 200px) min(var(--list-width), 280px) minmax(0, 1fr); }
}

/* Phone: one column, the panes stacked. */
@media (max-width: 760px) {
  .panes { grid-template-columns: minmax(0, 1fr); height: auto; }
  .pane { overflow: visible; }
  .pane-sidebar,
  .pane-list { border-right: 0; border-bottom: 1px solid var(--separator); }
  .topbar-app { display: none; }
}

/* ---- buttons and form fields ----------------------------------------------------------- */

.button {
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--separator);
  border-radius: var(--radius-s);
  background: var(--bg-raised);
  cursor: pointer;
}
.button:hover { background: var(--bg-hover); }
.button-primary { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.button-primary:hover { background: var(--accent); filter: brightness(0.94); }
.button-danger { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field label { font-size: var(--text-small); color: var(--text-secondary); }
.field input {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--separator);
  border-radius: var(--radius-s);
  background: var(--bg-raised);
}
.check { display: flex; align-items: center; gap: var(--space-2); }
.form-error { color: var(--danger); }

/* ---- segmented control (Day / Week / Month): a grey track and a white (dark: grey) pill ---- */

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius-s);
  background: var(--bg-track);
}
.segment {
  min-width: 56px;
  padding: 3px var(--space-3);
  border: 0;
  border-radius: 6px;
  font-size: var(--text-size);
  text-align: center;
  background: transparent;
  cursor: pointer;
}
.segment[aria-current="true"],
.segment[aria-pressed="true"] {
  font-weight: 600;
  background: var(--bg-segment);
  box-shadow: var(--shadow-segment);
}

/* ---- the settings sheet: a centred modal, sections on the left, the form on the right ------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: var(--backdrop);
}
.sheet {
  position: relative;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  width: min(790px, calc(100vw - 32px));
  height: min(590px, calc(100vh - 32px));
  overflow: hidden;
  border-radius: var(--radius-l);
  background: var(--bg-raised);
  box-shadow: var(--shadow);
}
.sheet-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-2);
  overflow: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-sidebar);
}
.sheet-close {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-bottom: var(--space-2);
  border-radius: 50%;
  color: var(--text-secondary);
}
.sheet-close:hover { background: var(--bg-hover); }
.sheet-section {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--row-height);
  padding: 0 var(--space-2);
  font-size: var(--text-row);
  border-radius: var(--radius-m);
}
.sheet-section:hover { background: var(--bg-hover); }
.sheet-section[aria-current="page"] { background: var(--bg-selected); }
.sheet-section-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; color: #fff; background: var(--tint, var(--accent)); }
.sheet-section-icon > .icon { width: 14px; height: 14px; }
.sheet-content { padding: var(--space-5); overflow: auto; }
.sheet-content h2 { font-size: var(--text-title); margin-bottom: var(--space-4); }
.tint-blue { --tint: #0071e3; }
.tint-red { --tint: #ff3b30; }
.tint-orange { --tint: #ff9500; }
.tint-green { --tint: #34c759; }
.tint-purple { --tint: #af52de; }
.tint-grey { --tint: #8e8e93; }

@media (max-width: 760px) {
  .sheet { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .sheet-nav { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border-sidebar); }
}

/* ---- confirmation dialog: a centred card, icon, bold title, one line, stacked buttons ------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: var(--backdrop);
}
.dialog-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: min(320px, calc(100vw - 32px));
  padding: var(--space-5) var(--space-4) var(--space-4);
  text-align: center;
  border-radius: var(--radius-l);
  background: var(--bg-raised);
  box-shadow: var(--shadow);
}
.dialog-icon { width: 40px; height: 40px; color: var(--accent); }
.dialog-card h2 { font-size: var(--text-large); font-weight: 700; }
.dialog-card p { color: var(--text-secondary); }
.dialog-actions { display: flex; flex-direction: column; gap: var(--space-2); width: 100%; margin-top: var(--space-3); }
.dialog-button {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-radius: var(--radius-m);
  font-size: var(--text-large);
  text-align: center;
  color: var(--text);
  background: var(--bg-track);
  cursor: pointer;
}
.dialog-button-primary { color: var(--accent-text); background: var(--accent-blue); }
.dialog-button-danger { color: var(--danger); }

/* ---- a live pane that changed under an edit ---------------------------------------------- */

.changed-elsewhere {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-selected);
  border-bottom: 1px solid var(--separator);
}
.changed-elsewhere[hidden] { display: none; }
.changed-elsewhere > span { flex: 1; }

/* ---- error pages ---------------------------------------------------------------------- */

.error-page {
  margin: auto;
  padding: var(--space-6) var(--space-4);
  text-align: center;
}
.error-page h1 { font-size: var(--text-title); margin-bottom: var(--space-2); }
.error-page p { color: var(--text-secondary); margin-bottom: var(--space-4); }
.error-page a { color: var(--accent); }

/* ---- the development spike page ------------------------------------------------------- */

.spike { max-width: 760px; margin: 0 auto; padding: var(--space-5) var(--space-4); }
.spike h1 { font-size: var(--text-title); margin-bottom: var(--space-3); }
.spike-editor {
  min-height: 160px;
  margin: var(--space-3) 0;
  padding: var(--space-3);
  border: 1px solid var(--separator);
  border-radius: var(--radius-s);
}
.spike button {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--separator);
  border-radius: var(--radius-s);
  background: var(--bg-raised);
}
.spike output { display: block; white-space: pre-wrap; margin-top: var(--space-3); color: var(--text-secondary); }

/* ---- sign-in -------------------------------------------------------------------------- */

.signin {
  flex: 1;
  display: grid;
  place-items: center;
  padding: var(--space-5) var(--space-4);
  background: var(--bg-sidebar);
}
.signin-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: min(360px, 100%);
  padding: var(--space-6) var(--space-5);
  border-radius: var(--radius-l);
  background: var(--bg-content);
  box-shadow: var(--shadow);
}
.signin-card > .icon { align-self: center; color: var(--accent); }
.signin-card h1 { font-size: var(--text-title); text-align: center; }

/* ---- settings -------------------------------------------------------------------------- */

.settings { max-width: 720px; width: 100%; margin: 0 auto; padding: var(--space-5) var(--space-4); }
.settings h1 { font-size: var(--text-title); margin-bottom: var(--space-4); }
.settings-section h2 { font-size: var(--text-large); margin-bottom: var(--space-2); }
.settings-note { color: var(--text-secondary); margin-bottom: var(--space-3); }
.browser-list { list-style: none; margin: 0 0 var(--space-4); padding: 0; }
.browser {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--separator);
}
.browser-info { display: flex; flex-direction: column; gap: 2px; }
.browser-name { font-weight: 600; }
.browser-badge { color: var(--accent); font-size: var(--text-small); }
.browser-detail { color: var(--text-secondary); font-size: var(--text-small); }
