:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --border: #e4e7ec;
  --border-soft: #edf1f5;
  --text: #111827;
  --muted: #667085;
  --muted-2: #98a2b3;

  --topbar-bg: linear-gradient(180deg, rgba(28, 34, 43, 0.98) 0%, rgba(21, 26, 34, 0.98) 100%);
  --topbar-text: rgba(255, 255, 255, 0.96);

  --sidebar-bg:
    radial-gradient(circle at top left, rgba(26, 42, 74, 0.42) 0%, rgba(10, 15, 24, 0) 38%),
    linear-gradient(180deg, #141a23 0%, #0b1119 100%);
  --sidebar-card: rgba(255, 255, 255, 0.055);
  --sidebar-border: rgba(255, 255, 255, 0.09);
  --sidebar-text: rgba(255, 255, 255, 0.95);
  --sidebar-muted: rgba(255, 255, 255, 0.70);
  --sidebar-hover: rgba(255, 255, 255, 0.085);
  --sidebar-active: rgba(255, 255, 255, 0.13);

  --button: #111827;
  --button-hover: #1f2937;

  --chip-bg: #ffffff;
  --chip-border: #d9dee7;
  --chip-active-bg: #eef2f6;
  --chip-active-border: #d4dbe5;

  --shadow: 0 10px 28px rgba(16, 24, 40, 0.06);
  --danger: #c81e1e;
  --danger-border: #f0c8c2;
  --danger-bg: #fff1f0;
  --success: #16a34a;

  --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);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

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

#app {
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* -------------------- TOPBAR -------------------- */

.topbar {
  min-height: 62px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + var(--safe-top)) calc(16px + var(--safe-right)) 8px calc(16px + var(--safe-left));
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow: hidden;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-left {
  flex: 1;
}

.topbar-right {
  flex-shrink: 0;
}

.topbar-menu-btn,
.topbar-link-btn {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.topbar-menu-btn {
  width: 36px;
  height: 36px;
  font-size: 18px;
  line-height: 1;
  flex: 0 0 auto;
}

.topbar-link-btn {
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.topbar-menu-btn:hover,
.topbar-link-btn:hover {
  background: rgba(255, 255, 255, 0.09);
}

.title {
  min-width: 0;
  flex: 1 1 auto;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #ffffff;
}

/* -------------------- LAYOUT -------------------- */

.container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  overflow-x: hidden;
}

.page-header {
  margin-bottom: 14px;
}

.page-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 800;
  color: var(--text);
}

.page-subtitle {
  margin: 6px 0 0 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

/* -------------------- CARDS -------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card.soft {
  border: 1px solid var(--border-soft);
  box-shadow: none;
}

/* -------------------- LOGIN -------------------- */

.login-wrap {
  min-height: calc(100dvh - 62px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(18px + var(--safe-top))
    18px
    calc(18px + var(--safe-bottom))
    18px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 16px 36px rgba(16, 24, 40, 0.08);
  margin-top: -20px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.login-brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: brightness(0) saturate(100%);
}

.login-brand-title {
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
}

.login-title {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
}

.login-subtitle {
  margin: 8px 0 18px 0;
  font-size: 13px;
  color: var(--muted);
}

/* -------------------- FORM -------------------- */

.form-row {
  margin-bottom: 12px;
}

.field-label {
  display: block;
  margin: 0 0 6px 0;
  font-size: 12px;
  font-weight: 700;
  color: #344054;
}

.input,
.select,
.time-select {
  width: 100%;
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid #d0d5dd;
  background: #ffffff;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  padding: 0 14px;
  outline: none;
  appearance: none;
}

.input:focus,
.select:focus,
.time-select:focus {
  border-color: #111827;
}

.input::placeholder {
  color: var(--muted-2);
}

/* -------------------- BUTTONS -------------------- */

.primary-btn,
.secondary-btn,
.icon-btn,
.delete-btn,
.mini-icon-btn {
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.04s ease, color 0.15s ease;
}

.primary-btn {
  width: 100%;
  min-height: 48px;
  border: none;
  background: var(--button);
  color: #ffffff;
  padding: 0 16px;
}

.primary-btn:hover {
  background: var(--button-hover);
}

.primary-btn:active,
.secondary-btn:active,
.icon-btn:active,
.delete-btn:active,
.mini-icon-btn:active {
  transform: translateY(1px);
}

.primary-btn:disabled,
.secondary-btn:disabled,
.icon-btn:disabled,
.delete-btn:disabled,
.mini-icon-btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.secondary-btn {
  min-height: 44px;
  border: 1px solid #d0d5dd;
  background: #ffffff;
  color: #344054;
  padding: 0 14px;
}

.secondary-btn:hover {
  background: #f8fafc;
  border-color: #98a2b3;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #d0d5dd;
  background: #ffffff;
  color: #344054;
  padding: 0 12px;
}

.icon-btn:hover {
  background: #f8fafc;
  border-color: #98a2b3;
}

.delete-btn {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--danger-border);
  background: #ffffff;
  color: var(--danger);
}

.delete-btn:hover {
  background: var(--danger-bg);
  border-color: #e5b4ab;
}

.mini-icon-btn {
  min-height: 40px;
  width: 40px;
  border: 1px solid #d0d5dd;
  background: #ffffff;
  color: #344054;
  padding: 0;
  line-height: 1;
}

.mini-icon-btn:hover {
  background: #f8fafc;
  border-color: #98a2b3;
}

/* -------------------- USER CARD -------------------- */

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar,
.sidebar-avatar {
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex: 0 0 auto;
}

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 23px;
  font-size: 16px;
}

.user-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.user-subtext {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}

/* -------------------- WEEK CARD -------------------- */

.week-card-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.week-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.week-meta {
  flex: 1;
  min-width: 0;
}

.week-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}

.week-range {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.week-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* -------------------- DAY BAR -------------------- */

.day-bar-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.day-bar-wrap::-webkit-scrollbar {
  display: none;
}

.day-bar {
  display: grid;
  grid-template-columns: repeat(7, minmax(74px, 1fr));
  gap: 8px;
  min-width: 560px;
}

.day-chip {
  position: relative;
  min-height: 68px;
  border-radius: 16px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  padding: 8px 8px 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.day-chip.active {
  background: var(--chip-active-bg);
  border-color: var(--chip-active-border);
}

.day-chip-name {
  font-size: 11px;
  font-weight: 700;
  color: #6b7280;
}

.day-chip.active .day-chip-name {
  color: var(--text);
}

.day-chip-date {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

.day-chip-add {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.day-chip.active .day-chip-add {
  background: #22c55e;
}

/* -------------------- SECTION -------------------- */

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.section-sub {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

/* -------------------- EMPTY -------------------- */

.empty-state {
  text-align: center;
  padding: 28px 18px;
}

.empty-title {
  margin: 0 0 6px 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.empty-subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

/* -------------------- ENTRY -------------------- */

.entry-card {
  padding: 14px;
}

.entry-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.entry-time {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.entry-meta {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.entry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.entry-grid-span-2 {
  grid-column: span 2;
}

.entry-subsection {
  margin-top: 12px;
}

.entry-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.entry-actions .secondary-btn,
.entry-actions .delete-btn {
  flex: 1;
}

.collapsed-card {
  padding: 12px 14px;
  cursor: pointer;
}

.entry-collapsed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.entry-collapsed-main {
  min-width: 0;
}

.entry-collapsed-side {
  flex: 0 0 auto;
}

.entry-complete-badge {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
}

.entry-complete-badge.complete {
  background: #22c55e;
  color: #ffffff;
}

.entry-complete-badge.incomplete {
  background: #e5e7eb;
  color: #6b7280;
}

.entries-swipe-zone {
  touch-action: pan-y;
}

/* -------------------- CHECKBOX -------------------- */

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 4px;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #111827;
}

.checkbox-row label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

/* -------------------- LUNCH -------------------- */

.lunch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

/* -------------------- TRAVEL + NOTES -------------------- */

.travel-row,
.notes-row {
  margin-top: 10px;
}

.travel-row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 110px;
  gap: 10px;
}

.inline-mini-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* -------------------- STATUS -------------------- */

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.status-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.status-text.saving {
  color: #b54708;
}

.status-text.saved {
  color: var(--success);
}

.status-text.error {
  color: var(--danger);
}

.success-text {
  margin-top: 10px;
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
}

.error-text {
  margin-top: 10px;
  color: #d92d20;
  font-size: 12px;
  font-weight: 700;
}

.add-row {
  margin-top: 12px;
}

/* -------------------- SIDEBAR -------------------- */

.hidden {
  display: none !important;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.50);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 90;
}

.sidebar-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: min(86vw, 320px);
  max-width: calc(100vw - 18px);
  height: 100dvh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  z-index: 100;
  color: var(--sidebar-text);
  overflow: hidden;
}

.sidebar-panel::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.sidebar-panel.open {
  transform: translateX(0);
}

.sidebar-panel-inner {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding:
    calc(18px + var(--safe-top))
    16px
    calc(18px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  color: var(--sidebar-text);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.sidebar-panel-inner::-webkit-scrollbar {
  display: none;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex: 0 0 auto;
}

.sidebar-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  color: #ffffff;
  max-width: 185px;
  word-break: break-word;
}

.sidebar-close-btn {
  width: 56px;
  height: 56px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.065);
  color: #ffffff;
  cursor: pointer;
  font-weight: 500;
  font-size: 22px;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.sidebar-close-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 auto;
}

.sidebar-nav-item {
  width: 100%;
  min-height: 52px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.055);
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  text-align: left;
  padding: 0 18px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 8px 18px rgba(0, 0, 0, 0.12);
}

.sidebar-nav-item.active,
.sidebar-nav-item:hover {
  background: var(--sidebar-active);
  border-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 18px;
  flex: 0 0 auto;
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 22px;
  padding: 14px 14px 14px 12px;
  margin-bottom: 12px;
  min-height: 92px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 12px 26px rgba(0, 0, 0, 0.18);
}

.sidebar-avatar {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.sidebar-user-meta {
  min-width: 0;
  flex: 1;
}

.sidebar-user-name {
  font-size: 15px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.15;
  white-space: normal;
  word-break: break-word;
}

.sidebar-user-level {
  font-size: 12px;
  font-weight: 500;
  color: var(--sidebar-muted);
  margin-top: 4px;
}

.sidebar-text-link {
  width: 100%;
  border: none;
  background: transparent;
  padding: 10px 2px;
  text-align: left;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.sidebar-text-link:hover {
  color: #ffffff;
}

.sidebar-text-link.danger {
  color: #fca5a5;
}

/* -------------------- MOBILE -------------------- */

@media (max-width: 640px) {
  .container {
    padding: 14px;
  }

  .page-title {
    font-size: 24px;
  }

  .week-card-row {
    flex-wrap: wrap;
    align-items: stretch;
  }

  .week-actions {
    width: 100%;
  }

  .week-actions .input {
    width: 100%;
  }

  .entry-grid {
    grid-template-columns: 1fr;
  }

  .entry-grid-span-2 {
    grid-column: span 1;
  }

  .travel-row-grid {
    grid-template-columns: 1fr;
  }

  .entry-actions {
    flex-direction: column;
  }

  .lunch-grid {
    grid-template-columns: 1fr;
  }

  .day-bar {
    min-width: 560px;
    grid-template-columns: repeat(7, 74px);
  }

  .sidebar-panel {
    width: min(88vw, 340px);
    max-width: calc(100vw - 12px);
  }

  .sidebar-title {
    font-size: 17px;
    max-width: 180px;
  }
}

@media (max-width: 560px) {
  .day-bar {
    min-width: 560px;
    grid-template-columns: repeat(7, 74px);
  }

  .title {
    font-size: 15px;
  }

  .topbar {
    padding:
      calc(8px + var(--safe-top))
      calc(12px + var(--safe-right))
      8px
      calc(12px + var(--safe-left));
  }

  .topbar-link-btn {
    padding: 0 8px;
    font-size: 12px;
  }

  .sidebar-panel-inner {
    padding-right: 14px;
  }

  .sidebar-user-card {
    border-radius: 20px;
  }
}