/* =========================================================
   RESET & BASE
   ========================================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg:          #f4f6f9;
  --color-surface:     #ffffff;
  --color-border:      #dde1e7;
  --color-text:        #1e2330;
  --color-text-muted:  #6b7280;
  --color-primary:     #2563eb;
  --color-primary-h:   #1d4ed8;
  --color-secondary:   #e5e7eb;
  --color-secondary-h: #d1d5db;
  --color-danger:      #dc2626;
  --color-danger-h:    #b91c1c;
  --color-success:     #16a34a;
  --color-warning:     #d97706;
  --radius:            6px;
  --shadow-sm:         0 1px 3px rgba(0,0,0,.08);
  --shadow-md:         0 4px 12px rgba(0,0,0,.1);
  --toolbar-h:         60px;
  --font:              'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* =========================================================
   TOOLBAR (header + footer)
   ========================================================= */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  min-height: var(--toolbar-h);
  padding: 8px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.toolbar--footer {
  top: auto;
  bottom: 0;
  border-bottom: none;
  border-top: 1px solid var(--color-border);
}

.toolbar__left,
.toolbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar__title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
}

/* =========================================================
   DATE INPUT
   ========================================================= */
.date-picker-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-input {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .9rem;
  color: var(--color-text);
  background: var(--color-bg);
  cursor: pointer;
  transition: border-color .15s;
  /* prevent iOS zoom on focus */
  font-size: max(.9rem, 16px);
}
.date-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 14px;
  min-height: 36px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
  user-select: none;
  /* minimum touch target */
  min-width: 36px;
}
.btn:active { transform: scale(.97); }

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}
.btn--primary:hover { background: var(--color-primary-h); }

.btn--secondary {
  background: var(--color-secondary);
  color: var(--color-text);
}
.btn--secondary:hover { background: var(--color-secondary-h); }

.btn--ghost {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  padding: 6px 10px;
  font-size: .8rem;
}
.btn--ghost:hover { background: rgba(37,99,235,.07); }

.btn--danger {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid transparent;
  padding: 5px 8px;
  font-size: .8rem;
}
.btn--danger:hover {
  background: rgba(220,38,38,.08);
  border-color: var(--color-danger);
}

.btn--icon {
  background: transparent;
  color: var(--color-text-muted);
  padding: 5px 7px;
  font-size: 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
}
.btn--icon:hover {
  background: var(--color-secondary);
  color: var(--color-text);
}

/* =========================================================
   SAVE STATUS
   ========================================================= */
.save-status {
  font-size: .8rem;
  color: var(--color-text-muted);
  transition: color .3s;
  white-space: nowrap;
}
.save-status--saving  { color: var(--color-warning); }
.save-status--saved   { color: var(--color-success); }
.save-status--error   { color: var(--color-danger); }

/* =========================================================
   MAIN CONTENT
   ========================================================= */
.main {
  flex: 1;
  padding: 24px 20px 90px; /* bottom pad for sticky footer */
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

/* =========================================================
   EMPTY STATE
   ========================================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 20px;
  text-align: center;
}
.empty-state__text {
  color: var(--color-text-muted);
  font-size: 1rem;
}
.hidden { display: none !important; }

/* =========================================================
   NOTES TABLE — desktop
   ========================================================= */
.table-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.notes-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.notes-table thead tr {
  background: #f8f9fb;
}

.notes-table th {
  padding: 11px 14px;
  text-align: left;
  font-size: .8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--color-border);
}

.col-num     { width: 48px; text-align: center; }
.col-note    { /* fill remaining */ }
.col-actions { width: 80px; text-align: center; }

.notes-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background .1s;
}
.notes-table tbody tr:last-child { border-bottom: none; }
.notes-table tbody tr:hover { background: #fafbfd; }

.notes-table td {
  padding: 10px 14px;
  vertical-align: top;
}

.td-num {
  text-align: center;
  color: var(--color-text-muted);
  font-size: .85rem;
  font-weight: 600;
  padding-top: 14px;
}

/* Editable textarea inside cell */
.note-textarea {
  width: 100%;
  min-height: 42px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-family: var(--font);
  font-size: .95rem;
  color: var(--color-text);
  background: transparent;
  resize: vertical;
  transition: border-color .15s, background .15s;
  line-height: 1.5;
  /* prevent iOS zoom on focus */
  font-size: max(.9rem, 16px);
}
.note-textarea:hover {
  border-color: var(--color-border);
  background: #f8f9fb;
}
.note-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.td-actions {
  text-align: center;
  vertical-align: middle;
}

/* =========================================================
   NOTES COUNT
   ========================================================= */
.notes-count {
  font-size: .85rem;
  color: var(--color-text-muted);
}

/* =========================================================
   TOAST
   ========================================================= */
.toast {
  position: fixed;
  bottom: 80px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--color-text);
  color: #fff;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .3s, transform .3s;
  pointer-events: none;
  z-index: 200;
  max-width: 320px;
}
.toast--show {
  opacity: 1;
  transform: translateY(0);
}
.toast--success { background: var(--color-success); }
.toast--error   { background: var(--color-danger); }

/* =========================================================
   ACCESSIBILITY
   ========================================================= */
.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;
}

/* =========================================================
   RESPONSIVE — tablet  (< 768px)
   ========================================================= */
@media (max-width: 768px) {
  .main {
    padding: 16px 14px 90px;
  }

  .toolbar {
    padding: 8px 14px;
    gap: 6px;
  }

  /* Shrink fixed columns a bit */
  .col-num     { width: 36px; }
  .col-actions { width: 64px; }

  .notes-table th,
  .notes-table td {
    padding: 8px 10px;
  }

  .td-num { padding-top: 12px; }
}

/* =========================================================
   RESPONSIVE — mobile  (< 480px)
   ========================================================= */
@media (max-width: 480px) {
  html { font-size: 14px; }

  /* ── Toolbar ── */
  .toolbar {
    padding: 6px 10px;
    /* two logical rows: left fills top, right fills bottom */
    flex-direction: column;
    align-items: stretch;
    min-height: auto;
  }

  .toolbar__left,
  .toolbar__right {
    width: 100%;
    justify-content: space-between;
  }

  /* Hide title to save horizontal space */
  .toolbar__title { display: none; }

  /* Date input stretches to fill available space */
  .date-picker-group { flex: 1; }
  .date-input        { flex: 1; }

  /* Save status hidden on mobile (toast is enough feedback) */
  .save-status { display: none; }

  /* Buttons fill equal space on mobile row */
  .toolbar__right .btn {
    flex: 1;
    font-size: .8rem;
    padding: 8px 6px;
    min-height: 40px;
  }

  /* ── Main ── */
  .main {
    padding: 12px 8px 100px;
  }

  /* ── Table: switch to card layout ── */
  .table-wrapper {
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }

  /* Hide table header */
  .notes-table thead { display: none; }

  /* Each row becomes a card */
  .notes-table,
  .notes-table tbody,
  .notes-table tr {
    display: block;
    width: 100%;
  }

  .notes-table tr {
    position: relative;
    padding: 10px 10px 10px 36px; /* left indent for row number */
    border-bottom: 1px solid var(--color-border);
  }
  .notes-table tbody tr:last-child { border-bottom: none; }
  .notes-table tbody tr:hover { background: #fafbfd; }

  /* Hide td borders/padding defaults */
  .notes-table td {
    display: block;
    padding: 0;
    border: none;
  }

  /* Row number — absolute top-left badge */
  .td-num {
    position: absolute;
    top: 12px;
    left: 0;
    width: 32px;
    font-size: .75rem;
    padding: 0;
    text-align: center;
  }

  /* Note textarea fills card width */
  .td-note { width: 100%; }

  .note-textarea {
    min-height: 50px;
    font-size: 1rem; /* comfortable on touch */
    padding: 4px 6px;
  }

  /* Delete button — top-right corner */
  .td-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    width: auto;
  }

  /* ── Toast ── */
  .toast {
    left: 10px;
    right: 10px;
    max-width: none;
    bottom: 90px;
    text-align: center;
  }
}

/* =========================================================
   RESPONSIVE — very small  (< 360px)
   ========================================================= */
@media (max-width: 360px) {
  .toolbar__right .btn {
    font-size: .75rem;
    padding: 7px 4px;
  }

  .date-input {
    font-size: .85rem;
  }

  .btn--ghost {
    padding: 5px 8px;
    font-size: .75rem;
  }
}
