:root {
  --bg: #eeece2;
  --surface: #fffdf8;
  --ink: #20261f;
  --ink-soft: #5c6259;
  --border: #dbd6c6;
  --accent: #3b5d50;
  --accent-soft: #e3ebe6;
  --amber: #b9793f;
  --amber-soft: #f3e5d3;
  --radius: 4px;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 36px 48px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  padding-right: 10px;
  border-right: 1px solid var(--border);
}

.user-name {
  color: var(--ink);
  font-weight: 600;
}

.role-tag {
  font-size: 10.5px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 12px;
  letter-spacing: 0.05em;
  display: inline-block;
}

.role-tag.admin {
  background: var(--accent-soft);
  color: var(--accent);
}

.role-tag.supervisor {
  background: var(--amber-soft);
  color: var(--amber);
}

.role-tag.viewer {
  background: #e6eaee;
  color: #435569;
}

.btn {
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  padding: 9px 15px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); background: rgba(59, 93, 80, 0.04); }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 20px 28px;
  padding: 16px 48px;
  font-size: 13px;
  color: var(--ink-soft);
}
.stats b { color: var(--ink); font-weight: 600; }

main {
  padding: 0 48px 60px;
  width: 100%;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
  white-space: nowrap;
}

tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 13.5px;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr.month-alt { background: #f7f5ec; }

.col-month, .col-week { width: 56px; text-align: center; }
.col-date { width: 105px; white-space: nowrap; }
.col-tasks { min-width: 180px; }
.col-note { min-width: 120px; }
.col-learned { min-width: 120px; }
.col-supervisor {
  display: none !important;
}
.col-options { width: 90px; min-width: 80px; text-align: right; }

.hide-options .col-options {
  display: none !important;
}

.month-badge {
  display: inline-block;
  min-width: 24px;
  text-align: center;
  font-weight: 600;
  color: var(--accent);
}
.week-badge { color: var(--ink-soft); }

.task-list { margin: 0; padding-left: 16px; }
.task-list li { margin-bottom: 4px; }
.task-list li:last-child { margin-bottom: 0; }

.link-title {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
}
.link-title:hover { text-decoration-color: var(--accent); }
.link-title.learned { color: var(--amber); }
.link-title.learned:hover { text-decoration-color: var(--amber); }
.link-title.empty { color: var(--ink-soft); text-decoration: none; cursor: default; }

/* Supervisor comment UI in table */
.supervisor-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.supervisor-preview {
  display: inline-block;
  font-size: 13px;
  color: var(--ink);
  line-height: 1.4;
  word-break: break-word;
  background: var(--amber-soft);
  padding: 6px 10px;
  border-radius: var(--radius);
  border-left: 3px solid var(--amber);
}

.btn-supervisor-action {
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--amber);
  cursor: pointer;
  padding: 4px 8px;
  align-self: flex-start;
  transition: all 0.15s ease;
  touch-action: manipulation;
}
.btn-supervisor-action:hover {
  background: var(--amber-soft);
  border-color: var(--amber);
}

.row-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.row-actions button {
  background: none;
  border: none;
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px;
  touch-action: manipulation;
}
.row-actions button:hover { color: var(--accent); }
.row-actions button.delete:hover { color: #a33b2c; }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}

/* Modals */
.overlay {
  position: fixed; inset: 0;
  background: rgba(20, 24, 19, 0.5);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
  overflow-y: auto;
}

.overlay[hidden], .panel-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px 30px 30px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  margin: auto;
}

.modal-sm {
  max-width: 480px;
}

.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px;
}
.modal-head h2 { font-family: var(--serif); font-size: 22px; margin: 0; line-height: 1.2; }

.draft-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--amber-soft);
  color: var(--ink);
  border: 1px solid rgba(185, 121, 63, 0.35);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 16px;
  font-size: 13px;
  animation: fadeIn 0.2s ease-in;
}

.draft-banner-text {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
}

.draft-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  display: inline-block;
}

.btn-discard-draft {
  background: none;
  border: none;
  color: #a04e22;
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius);
  text-decoration: underline;
  transition: background 0.15s ease;
}

.btn-discard-draft:hover {
  background: rgba(160, 78, 34, 0.1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: translateY(0); }
}

.icon-btn {
  background: none; border: none; font-size: 24px; line-height: 1;
  cursor: pointer; color: var(--ink-soft); padding: 6px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: var(--ink); background: rgba(0,0,0,0.05); }

label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.6fr;
  gap: 12px;
}
.field-row label {
  margin-bottom: 14px;
}

.field-block { display: block; }
.field-pair { border-top: 1px solid var(--border); padding-top: 14px; margin-bottom: 4px; }

input, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  resize: vertical;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.hint { font-weight: 400; color: var(--ink-soft); font-size: 11.5px; }

.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 16px;
}

/* Side panel */
.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 24, 19, 0.35);
  backdrop-filter: blur(1px);
  z-index: 60;
}

.side-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 28px 26px;
  overflow-y: auto;
  box-shadow: -8px 0 24px rgba(0,0,0,0.08);
}

.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 8px;
}

#panelTitle { font-family: var(--serif); font-size: 21px; margin: 0 0 16px; line-height: 1.3; }
.panel-content { white-space: pre-wrap; color: var(--ink); font-size: 14px; line-height: 1.7; }

/* Login page styling */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
}

.login-container {
  width: 100%;
  max-width: 420px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}

.login-header {
  margin-bottom: 24px;
}

.login-subtitle {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  margin-bottom: 0;
}

.login-btn {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  font-size: 14.5px;
}

.alert-error {
  background: #fae8e6;
  color: #a33b2c;
  border: 1px solid #f1c5c0;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 18px;
}

/* ==========================================================
   Responsive Breakpoints & Mobile Enhancements
   ========================================================== */

@media (max-width: 900px) {
  .page-header {
    padding: 28px 24px 20px;
  }
  .stats {
    padding: 14px 24px;
  }
  main {
    padding: 0 24px 48px;
  }
}

@media (max-width: 768px) {
  /* Ensure inputs have at least 16px font size to prevent iOS auto-zoom on focus */
  input, textarea, select {
    font-size: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 24px 16px 16px;
  }

  h1 {
    font-size: 26px;
  }

  .header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .user-profile {
    border-right: none;
    padding-right: 0;
    width: 100%;
    margin-bottom: 2px;
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--border);
    justify-content: space-between;
  }

  .header-actions .btn {
    flex: 1 1 calc(50% - 8px);
    font-size: 13px;
    padding: 8px 12px;
    text-align: center;
  }

  .header-actions .btn#addBtn {
    flex: 1 1 100%;
    order: -1;
    padding: 10px 14px;
    font-size: 14px;
  }

  .stats {
    padding: 12px 16px;
    gap: 8px 16px;
    font-size: 12.5px;
  }

  main {
    padding: 0 16px 40px;
  }

  .field-row {
    grid-template-columns: 1fr 1fr;
  }
  .field-row label:last-child {
    grid-column: span 2;
  }

  .side-panel {
    width: 100vw;
    max-width: 100vw;
    border-left: none;
    padding: 20px 18px 36px;
  }

  .login-card {
    padding: 28px 20px;
  }
}

@media (max-width: 480px) {
  .page-header {
    padding: 20px 12px 14px;
  }

  h1 {
    font-size: 23px;
  }

  .header-actions .btn {
    flex: 1 1 100%;
  }

  .stats {
    padding: 10px 12px;
    flex-direction: column;
    gap: 4px;
  }

  main {
    padding: 0 12px 32px;
  }

  .overlay {
    padding: 12px 8px;
  }

  .modal {
    padding: 18px 16px 20px;
    max-height: 94vh;
  }

  .modal-head h2 {
    font-size: 19px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
  .field-row label:last-child {
    grid-column: span 1;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-actions .btn {
    width: 100%;
    padding: 11px;
  }

  .login-card {
    padding: 24px 16px;
  }
}

