/* Keep's look, from miPortal's design tokens (light theme). */

:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --text: #1B1B1B;
  --muted: #6B6B6B;
  --border: #E8E8E8;
  --divider: #F0F0F0;
  --primary: #1B3A4B;
  --accent: #C6975B;
  --danger: #C0392B;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius: 8px;
  --tap: 44px;
  --content: 672px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

/* Padded by the safe-area insets: clear of the notch and the home bar. */
body {
  margin: 0;
  min-height: 100vh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Top bar: its white runs up under the notch. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  margin-top: calc(-1 * var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--surface);
}

/* The bar itself: a full-width 56px white row with a 1px bottom border, its title
   on the left of the 672px content column. */
.topbar-inner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 56px;
  padding: 0 max(var(--space-4), calc((100% - var(--content)) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-lead {
  display: flex;
  flex: none;
  margin-left: calc(-1 * var(--space-2));
}

.topbar-lead:empty {
  display: none;
}

.topbar-back {
  gap: 2px;
  padding: 0 var(--space-2) 0 var(--space-1);
}

.topbar-back > span {
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
  margin-right: calc(-1 * var(--space-2));
}

/* Content: centred, at most 672px wide, 16px side padding. */
main {
  max-width: var(--content);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(var(--space-6) + 56px);
  box-sizing: content-box;
}

.section-label,
.label {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.section-label {
  margin: var(--space-5) 0 var(--space-2);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

main > .section-label:first-child {
  margin-top: var(--space-2);
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

/* Cards: 1px border, radius 8, no shadow. */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
}

.form-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* List rows: 12px padding, 1px divider, 36px icon tile, title and subtitle. */
.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-3);
  border: 0;
  border-bottom: 1px solid var(--divider);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
}

.list > :last-child > .row,
.list > .row:last-child {
  border-bottom: 0;
}

button.row,
a.row {
  cursor: pointer;
}

.tile {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: rgba(27, 58, 75, 0.08);
  color: var(--primary);
}

.row-body {
  flex: 1;
  min-width: 0;
}

.row-title {
  display: block;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.row-meta {
  flex: none;
  font-size: 12px;
  color: var(--muted);
}

/* Buttons: radius 8, 14px text, at least 44px high. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn:focus-visible,
.row:focus-visible,
.fab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #FFFFFF;
}

.btn-plain {
  background: none;
  color: var(--primary);
}

.btn-icon {
  min-width: var(--tap);
  padding: 0 var(--space-2);
}

.btn-block {
  width: 100%;
}

/* Floating add button: teal pill with a shadow, bottom right. */
.fab {
  position: fixed;
  right: calc(var(--space-4) + var(--safe-right));
  bottom: calc(var(--space-4) + var(--safe-bottom));
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-5) 0 var(--space-4);
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #FFFFFF;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(27, 58, 75, 0.3), 0 1px 3px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

/* Inputs: 1px border, radius 8, teal border on focus. 16px text keeps iOS from zooming in. */
.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Notes; an error note is a 10% danger fill with a 40% border, never red text. */
.note {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

.note-error {
  background: rgba(192, 57, 43, 0.1);
  border-color: rgba(192, 57, 43, 0.4);
}

.empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--muted);
}

.empty-title {
  margin-bottom: var(--space-1);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* A failed load: the error note with a way to try again. */
.state {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Bottom sheets: 40% black backdrop, white panel with 16px top corners. */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
}

.sheet {
  width: 100%;
  max-width: calc(var(--content) + 2 * var(--space-4));
  max-height: calc(100% - var(--safe-top) - var(--space-6));
  overflow-y: auto;
  padding: var(--space-2) calc(var(--space-4) + var(--safe-right)) calc(var(--space-4) + var(--safe-bottom))
    calc(var(--space-4) + var(--safe-left));
  border-radius: 16px 16px 0 0;
  background: var(--surface);
}

dialog.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  border: 0;
  color: var(--text);
}

dialog.sheet::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.sheet-grabber {
  width: 40px;
  height: 4px;
  margin: 0 auto var(--space-2);
  border-radius: 2px;
  background: var(--border);
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.sheet-title {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* A record's screen: one card per section, then its actions. */
.sections {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.record-section > .row {
  border-bottom: 0;
}

.record-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.record-actions > .btn {
  flex: 1;
}

/* A note's screen: the Edit / Preview switch and the save status, then the
   toolbar and text area, or the rendered preview. */
.note-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.segmented {
  display: flex;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.segment {
  padding: 0 var(--space-3);
  border-radius: 7px;
  background: none;
  color: var(--muted);
}

.segment[aria-pressed="true"] {
  background: var(--primary);
  color: #FFFFFF;
}

.save-status {
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.save-status.save-failed,
.save-status.save-signin {
  padding: var(--space-1) var(--space-2);
  border: 1px solid rgba(192, 57, 43, 0.4);
  border-radius: var(--radius);
  background: rgba(192, 57, 43, 0.1);
  color: var(--text);
}

/* Shown on a note whose save needs signing in again (D-0009). */
.note-sign-in {
  margin-bottom: var(--space-3);
}

/* The Microsoft account card under the records folder form. */
.account {
  margin-top: var(--space-4);
}

/* The toolbar scrolls sideways inside itself when it can't fit, never the page. */
.toolbar {
  display: flex;
  gap: 2px;
  margin: 0 calc(-1 * var(--space-3)) var(--space-2);
  padding: 0 var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.tool {
  flex: none;
  width: var(--tap);
  padding: 0;
  color: var(--text);
}

.note-editor {
  display: block;
  min-height: 50vh;
  resize: vertical;
  line-height: 1.5;
}

/* The preview: Markdown rendered in the app's type. */
.note-preview {
  min-height: 50vh;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px;
  line-height: 1.5;
  cursor: text;
}

.markdown > * + * {
  margin-top: var(--space-3);
}

.markdown h1 { font-size: 22px; font-weight: 600; }
.markdown h2 { font-size: 19px; font-weight: 600; }
.markdown h3 { font-size: 17px; font-weight: 600; }
.markdown h4, .markdown h5, .markdown h6 { margin-bottom: 0; font-size: 16px; font-weight: 600; }

.markdown ul,
.markdown ol {
  margin-bottom: 0;
  padding-left: var(--space-5);
}

.markdown ul ul,
.markdown ul ol,
.markdown ol ul,
.markdown ol ol {
  margin-top: 0;
}

.markdown a {
  color: var(--primary);
  text-decoration: underline;
}

.markdown blockquote {
  margin-left: 0;
  margin-right: 0;
  padding-left: var(--space-3);
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.markdown code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--divider);
  font-size: 14px;
}

.markdown hr {
  border: 0;
  border-top: 1px solid var(--border);
}

/* Checklist items: no bullet, a 44px tap area round each box. */
.markdown li.task {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  list-style: none;
  margin-left: calc(-1 * var(--space-5));
}

.markdown li.task > ul,
.markdown li.task > ol {
  flex-basis: 100%;
  padding-left: calc(var(--space-5) + 32px);
}

.task-box {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tap);
  height: var(--tap);
  margin-left: -12px;
}

/* The box itself fills the 44px area; its 20px square is drawn inline. */
.task-box input {
  width: var(--tap);
  height: var(--tap);
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: var(--radius);
  background: no-repeat center / 20px 20px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Crect x='1' y='1' width='18' height='18' rx='4' fill='%23FFFFFF' stroke='%236B6B6B' stroke-width='1.5'/%3E%3C/svg%3E");
  cursor: pointer;
}

.task-box input:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Crect x='1' y='1' width='18' height='18' rx='4' fill='%231B3A4B' stroke='%231B3A4B' stroke-width='1.5'/%3E%3Cpath d='M5.5 10.5l3 3 6-7' fill='none' stroke='%23FFFFFF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.task-box input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -4px;
}

.task-text {
  flex: 1;
  min-width: 0;
  padding-top: 10px;
}

/* A media section: the uploads under way, then the section's items. */
.uploads {
  margin-bottom: var(--space-3);
}

.upload-progress {
  display: block;
  width: 100%;
  height: 4px;
  margin-top: var(--space-1);
  border: 0;
  border-radius: 2px;
  background: var(--divider);
  appearance: none;
  -webkit-appearance: none;
}

.upload-progress::-webkit-progress-bar {
  border-radius: 2px;
  background: var(--divider);
}

.upload-progress::-webkit-progress-value {
  border-radius: 2px;
  background: var(--primary);
}

.upload-progress::-moz-progress-bar {
  border-radius: 2px;
  background: var(--primary);
}

/* A failed upload: an error note, a 10% fill with a 40% border, never red text. */
.upload-failed > .row,
.list > :last-child.upload-failed > .row {
  border: 1px solid rgba(192, 57, 43, 0.4);
  border-radius: var(--radius);
  background: rgba(192, 57, 43, 0.1);
}

.upload-failed .tile {
  border: 1px solid rgba(192, 57, 43, 0.4);
  background: rgba(192, 57, 43, 0.1);
  color: var(--text);
}

.upload-failed .row-sub {
  color: var(--text);
}

/* Photos: square thumbnails, three to a row. The image is laid over its tile
   rather than sized by it, so a very tall or wide photo is cropped to the square. */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.photo-tile {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  background: var(--divider);
  color: var(--muted);
  cursor: pointer;
}

.photo-tile img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-tile:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* The full-screen viewer: a bar with Back, the item fitted to the screen, and
   previous and next; clear of the notch and the home bar. */
body.viewing {
  overflow: hidden;
}

/* The screen under the viewer is out of reach until it closes. */
body.viewing > .topbar,
body.viewing > main {
  visibility: hidden;
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: #000000;
  color: #FFFFFF;
}

.viewer-bar,
.viewer-nav {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  height: 56px;
  padding: 0 var(--space-2);
}

.viewer .btn-plain {
  color: #FFFFFF;
}

.viewer-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-nav {
  justify-content: space-between;
}

.viewer-count {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.viewer-stage {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pinch-zoom;
}

/* Laid over the stage, so its own shape never sizes it: always fitted inside. */
.viewer-media {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.viewer-note {
  margin: var(--space-4);
  color: #FFFFFF;
}

/* A video that can't play: the note over the top of its player. */
.viewer-note-over {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
}

/* Videos and Files: a row opens the item; a file's row has its delete control. */
.media-item {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--divider);
}

.media-list > .media-item:last-child {
  border-bottom: 0;
}

.media-item > .row {
  flex: 1;
  min-width: 0;
  border-bottom: 0;
}

.row-delete {
  flex: none;
  margin-right: var(--space-1);
  color: var(--muted);
}

/* A video's thumbnail in its row: wider than an icon tile, radius 8. */
.row-thumb {
  display: grid;
  place-items: center;
  flex: none;
  width: 64px;
  height: 48px;
  overflow: hidden;
  border-radius: var(--radius);
  background: rgba(27, 58, 75, 0.08);
  color: var(--primary);
}

.row-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* A file Keep can't show: its details and Open in OneDrive. */
.file-details .row-title {
  white-space: normal;
}

/* A PDF: its pages one under the other, at the content's width. */
.pdf-pages {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.pdf-page {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #FFFFFF;
}

.pdf-page canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* A sketch's preview in its row: white like the canvas, the drawing fitted inside. */
.sketch-thumb {
  display: grid;
  place-items: center;
  flex: none;
  width: 64px;
  height: 48px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #FFFFFF;
  color: var(--primary);
}

.sketch-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* The sketch canvas: full screen over the app, inside the safe areas. The page
   under it neither scrolls nor zooms; touches act on the canvas. */
html.sketching,
body.sketching {
  overflow: hidden;
  overscroll-behavior: none;
}

body.sketching > .topbar,
body.sketching > main {
  visibility: hidden;
}

.sketch-editor {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  overflow: hidden;
  background: var(--surface);
  overscroll-behavior: none;
  touch-action: none;
}

.sketch-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
  height: 56px;
  padding: 0 var(--space-2);
  border-bottom: 1px solid var(--border);
}

.sketch-close {
  gap: var(--space-1);
  padding: 0 var(--space-2);
}

.sketch-heading {
  flex: 1;
  min-width: 0;
}

.sketch-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sketch-state {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sketch-error {
  flex: none;
  margin: var(--space-2) var(--space-2) 0;
}

.sketch-canvas {
  position: relative;
  flex: 1;
  min-height: 0;
}

.sketch-stage {
  position: absolute;
  inset: 0;
}

.sketch-message:not(:empty) {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: var(--space-4);
  background: var(--surface);
}

/* A further line of a checklist item: its own row, under the item's text. */
.task-more {
  flex-basis: 100%;
  min-width: 0;
  padding-left: 32px;
}
