/* Styled after the default Home Assistant (Lovelace) theme: blue app header with the
   view tabs in it, flat cards with a thin border, filled text fields, Roboto. */

/* Roboto is bundled in static/fonts (SIL Open Font License, see Roboto-LICENSE.txt),
   so it looks the same on every device. Latin subset: covers å, ä, ö. */
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/roboto-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/roboto-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}
:root {
  --background: #fafafa;
  --surface: #ffffff;
  --field: #f5f5f5;
  --text: #212121;
  --muted: #727272;
  --border: #e0e0e0;
  --divider: rgba(0, 0, 0, 0.12);
  --accent: #03a9f4;
  --accent_text: #ffffff;
  --accent_soft: rgba(3, 169, 244, 0.12);
  --header: #03a9f4;
  --header_text: #ffffff;
  --icon: #44739e;
  --danger: #db4437;
  --done: #9e9e9e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #111111;
    --surface: #1c1c1c;
    --field: #2a2a2a;
    --text: #e1e1e1;
    --muted: #9b9b9b;
    --border: #2f2f2f;
    --divider: rgba(225, 225, 225, 0.12);
    --accent: #03a9f4;
    --accent_text: #ffffff;
    --accent_soft: rgba(3, 169, 244, 0.18);
    --header: #101e24;
    --header_text: #e1e1e1;
    --icon: #9b9b9b;
    --danger: #ef5350;
    --done: #6f6f6f;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Roboto, "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------- header and tabs */

.top_bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 0;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--header);
  color: var(--header_text);
}

.top_bar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.25rem;
  font-weight: 400;
}

.user_name { opacity: 0.8; font-size: 0.9rem; }

.top_bar .text_button { color: var(--header_text); }

.connection_status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4caf50;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}
.connection_status.offline { background: var(--danger); }

.tab_bar {
  display: flex;
  background: var(--header);
  padding: 0 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.14);
}

.tab_button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font-weight: 500;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  color: var(--header_text);
  opacity: 0.7;
  cursor: pointer;
}
.tab_button.active {
  opacity: 1;
  border-bottom-color: var(--header_text);
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

/* ----------------------------------------------------------------- cards */

/* All lists are shown on top of each other; the page scrolls through them. */
.add_list_button {
  width: 100%;
  min-height: 36px;
  margin-bottom: 8px;
  border: 1px dashed var(--divider);
  border-radius: 12px;
  background: none;
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}
.add_list_button:hover { background: var(--accent_soft); }
.list_stack { display: flex; flex-direction: column; gap: 8px; }

/* Phones: "+ Ny inköpslista" floats at the bottom of the screen, within thumb reach,
   and the lists get room at the bottom so the last one can scroll clear of it. */
@media (max-width: 799px) {
  #new_shopping_list_button {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 5;
    width: auto;
    min-height: 48px;
    margin: 0;
    padding: 0 24px;
    transform: translateX(-50%);
    border: 0;
    border-radius: 24px;
    background: var(--accent);
    color: var(--accent_text);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  }
  #new_shopping_list_button:hover { background: var(--accent); filter: brightness(1.08); }
  #shopping_view { padding-bottom: 80px; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
}

.panel_header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.panel_header h2 { margin: 0; font-size: 1.3rem; font-weight: 400; }
/* margin-left: auto keeps the buttons on the right, also on wide screens where the
   back button beside them is hidden. */
.panel_actions { display: flex; gap: 2px; flex-wrap: wrap; align-items: center; margin-left: auto; }

/* --------------------------------------------------------------- buttons */

.text_button {
  min-height: 34px;
  padding: 2px 12px;
  border: 0;
  border-radius: 18px;
  background: none;
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}
.text_button:hover { background: var(--accent_soft); }
.top_bar .text_button:hover { background: rgba(255, 255, 255, 0.15); }
.text_button.danger { color: var(--danger); }

.icon_button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon_button:hover { background: var(--divider); }
.icon_button.danger:hover, .icon_button.danger:focus-visible { color: var(--danger); }

.primary_button {
  min-height: 36px;
  padding: 4px 16px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent_text);
  font-weight: 500;
  cursor: pointer;
}
.primary_button:hover { filter: brightness(1.08); }

/* ---------------------------------------------------- filled text fields */

input[type="text"], input[type="password"], textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  border-bottom: 1px solid var(--muted);
  border-radius: 4px 4px 0 0;
  background: var(--field);
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus {
  outline: none;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 7px;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.add_row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.icon_submit_button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
}
/* The plus beside the delete icon turns into an x while the add field is open. */
.show_add_button svg { transition: transform 0.15s ease; }
.show_add_button.open { color: var(--accent); }
.show_add_button.open svg { transform: rotate(45deg); }

/* ------------------------------------------------------------------ items */

.item_list, .note_list { list-style: none; margin: 0; padding: 0; }

.item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.item label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  cursor: pointer;
  word-break: break-word;
}
.item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: none;
  accent-color: var(--accent);
}
.item.done span { text-decoration: line-through; color: var(--done); }

/* Drag an item by its handle to move it. */
.drag_handle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 28px;
  height: 36px;
  margin-left: -6px;
  color: var(--muted);
  opacity: 0.6;
  cursor: grab;
  touch-action: none;  /* lets a finger drag the item instead of scrolling the page */
  user-select: none;
  -webkit-user-select: none;
}
.item.dragging {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.item.dragging .drag_handle { color: var(--accent); opacity: 1; }
body.dragging_active { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.item .remove_button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}
.item .remove_button:hover { background: var(--divider); }

.empty_message { color: var(--muted); text-align: center; margin: 10px 0 4px; }

/* -------------------------------------------------- list and note pickers */

.note_entry {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.note_entry:hover { background: var(--divider); }
.note_entry.active { background: var(--accent_soft); }
.note_entry .note_entry_title { font-weight: 500; display: block; }
.note_entry .note_entry_meta { color: var(--muted); font-size: 0.85rem; display: block; }

/* ------------------------------------------------------------- note editor */

/* The note reads like a page, not a form: a large title without a field around it, a
   thin line, then the text. "input.": must beat the filled-field rules above. The line
   is drawn by the title row, so it also runs under the delete icon. */
.note_title_row { padding-bottom: 4px; border-bottom: 1px solid var(--divider); }
input.note_title_input,
input.note_title_input:focus {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 6px 2px;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1.3;
}
input.note_title_input::placeholder { color: var(--muted); font-weight: 400; }

.note_body_input {
  position: relative;
  min-height: 55vh;
  padding: 12px 2px 16px;
  outline: none;
  font-size: 1.05rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  caret-color: var(--accent);
}
/* contenteditable has no placeholder of its own. */
.note_body_input.empty::before {
  content: attr(data-placeholder);
  position: absolute;
  color: var(--muted);
  pointer-events: none;
}
.note_body_input a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* Below the text, and stuck to the bottom of the screen while a long note scrolls. */
.note_toolbar {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  margin: 0 -12px;
  padding: 6px 10px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--divider);
  background: var(--surface);
}
.format_button { color: var(--text); border-radius: 8px; }
.format_button.active { background: var(--accent_soft); color: var(--accent); }
.toolbar_divider { width: 1px; height: 22px; margin: 0 6px; background: var(--divider); }

.note_status { color: var(--muted); font-size: 0.8rem; margin: 6px 0 0; text-align: right; }

/* The link dialog: a card in the middle of the dimmed page. */
.link_dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 16px 18px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.link_dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.link_dialog h2 { margin: 0 0 14px; font-size: 1.2rem; font-weight: 500; }
.link_dialog label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 0.85rem; }
.link_dialog input { margin-top: 4px; color: var(--text); font-size: 1rem; }
.link_error { margin: -4px 0 10px; color: var(--danger); font-size: 0.85rem; }
.dialog_buttons { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
/* Removing sits apart on the left, away from Spara. */
.dialog_buttons .danger { margin-right: auto; padding-left: 6px; }

.conflict_banner {
  margin-bottom: 6px;
  padding: 6px 12px;
  border-left: 4px solid var(--danger);
  border-radius: 4px;
  background: var(--field);
}
.conflict_banner p { margin: 0 0 4px; }

/* Listor and Anteckningar. Phones: show either the picker or the open list/note. */
.split_layout.editing .picker_panel { display: none; }
.back_button { padding-left: 4px; }
/* The open list's or note's title, with its buttons on the same row to the right. */
.detail_header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.detail_header .panel_actions { flex: none; flex-wrap: nowrap; }
.detail_title { flex: 1; min-width: 0; margin: 0; font-size: 1.3rem; font-weight: 400; word-break: break-word; }

/* Wide screens: picker and open list/note side by side. */
@media (min-width: 800px) {
  .split_layout { display: grid; grid-template-columns: 260px 1fr; gap: 8px; align-items: start; }
  .split_layout.editing .picker_panel { display: block; }
  .back_row { display: none; }
  .note_body_input { min-height: 60vh; }
}

/* ------------------------------------------------------------- login page */

.login_page {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(var(--header) 0 200px, var(--background) 200px);
}
.login_card {
  width: 100%;
  max-width: 360px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.login_card h1 { margin: 0 0 16px; font-size: 1.5rem; font-weight: 400; }
.login_card label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 0.85rem; }
.login_card input { margin-top: 4px; color: var(--text); }
.login_card .primary_button { width: 100%; margin-top: 4px; }
.login_error { color: var(--danger); margin: 0 0 12px; }
