@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600;700&family=IBM+Plex+Sans:wght@400;600;700&family=VT323&display=swap');

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #9a8470 0%, #7a6a50 50%, #6a5a40 100%);
  font-family: "IBM Plex Sans", "Courier New", sans-serif;
}

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

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #6a3a2a 0%, #5a2a1a 100%);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-bottom: 2px solid #3a1a0a;
}

.app-name {
  margin: 0;
  color: #d4b896;
  font-family: "IBM Plex Sans", "Courier New", sans-serif;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  transform: skewY(-2deg);
  white-space: nowrap;
}

.calc-display {
  display: flex;
  padding: 4px 12px;
  background: linear-gradient(180deg, #0a0805 0%, #1a1410 100%);
  border: 2px solid #2a1a0a;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px #4a3a2a, inset 0 2px 4px rgba(0, 0, 0, 0.8);
  flex: 1;
  min-width: 120px;
}

.display-segment {
  color: #b8a888;
  font-family: "VT323", "IBM Plex Mono", monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-shadow: 0 0 4px rgba(184, 168, 136, 0.4);
  flex: 1;
  text-align: center;
}

.nav-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 2px solid #3a2a1a;
  border-radius: 2px;
  background: linear-gradient(180deg, #d4b896 0%, #c4a886 50%, #a48860 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
  color: #1a1410;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-btn:active {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  transform: translate(0, 1px);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 14px;
  margin: 12px 16px 0;
  padding: 12px 12px 10px;
  background: linear-gradient(180deg, #a89870, #8a7850);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.toolbar label, dialog label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: #4a3a2a;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-family: "IBM Plex Sans", "Courier New", sans-serif;
}

.toolbar .grow { flex: 1 1 240px; max-width: 420px; min-width: 180px; }

.toolbar input, .toolbar select, dialog input {
  min-height: 36px;
  padding: 6px 10px;
  border: 2px solid #3a2a1a;
  border-radius: 2px;
  background: linear-gradient(180deg, #f4f0e8, #e4dcc8);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 2px 0 rgba(0, 0, 0, 0.15);
  color: #1a1410;
  font: bold 14px "IBM Plex Mono", "Courier New", monospace;
  letter-spacing: 0.5px;
  text-transform: none;
}

.toolbar input:focus, .toolbar select:focus, dialog input:focus {
  outline: none;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 3px #c89a3e;
}

.toolbar button, dialog button, .add-photo {
  height: 36px;
  padding: 0 14px;
  border: 2px solid #3a2a1a;
  border-radius: 2px;
  background: linear-gradient(180deg, #e8c56a 0%, #d4a850 50%, #b88830 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 3px 6px rgba(0, 0, 0, 0.25);
  color: #1a1410;
  font: bold 12px "IBM Plex Sans", "Courier New", sans-serif;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
}

.toolbar button:active, dialog button:active, .add-photo:active {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.25);
  transform: translate(0, 1px);
}

.toolbar button.secondary, dialog button.secondary {
  background: linear-gradient(180deg, #4a3a2a, #2a1a0a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 3px 6px rgba(0, 0, 0, 0.25);
  color: #d4b896;
}

.save-state {
  align-self: center;
  min-width: 72px;
  color: #4a3a2a;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-align: right;
  text-transform: uppercase;
  font-family: "IBM Plex Sans", "Courier New", sans-serif;
}

.notice {
  margin: 0 16px;
  padding: 8px 12px;
  border-radius: 2px;
  background: linear-gradient(180deg, #f4d878, #e8c862);
  border: 1px solid #d4a840;
  color: #1a1410;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  font-family: "IBM Plex Mono", "Courier New", monospace;
}

.notice.preview {
  background: linear-gradient(180deg, #d8e8c8, #c8d8a8);
  border-color: #b8c884;
  color: #2a3a1a;
}

.sheet-scroll {
  flex: 1;
  margin: 12px 16px;
  overflow: auto;
  background: transparent;
}

.sheet {
  width: 100%;
  min-width: 920px;
  border-collapse: separate;
  border-spacing: 4px 2px;
  table-layout: fixed;
}

.sheet th, .sheet td {
  border: 0;
  font-weight: 400;
}

.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: center;
  vertical-align: bottom;
}

.sheet th.corner, .sheet td.time {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 30px;
  border: 0;
  background: transparent;
}

.sheet thead th.corner { z-index: 4; }

.sheet td.time {
  padding: 6px 4px 6px 0;
  color: #f5f5f5;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  font-family: "VT323", "IBM Plex Mono", monospace;
}

.date-num {
  color: #f5f5f5;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  line-height: 1.2;
  font-family: "VT323", "IBM Plex Mono", monospace;
}

.date-day {
  margin-top: 2px;
  color: #f5f5f5;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  line-height: 1.2;
  font-family: "VT323", "IBM Plex Mono", monospace;
}

.date-lodging {
  margin-top: 4px;
  padding: 3px 4px;
  background: #dcc8b8;
  border: 1px solid #8a7850;
  border-radius: 3px;
  color: #1a1410;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: "IBM Plex Sans", "Courier New", sans-serif;
}

.sheet thead th {
  padding: 0 0 6px 0;
}

.sheet td.slot {
  height: 48px;
  padding: 0;
  vertical-align: middle;
  cursor: text;
  overflow: hidden;
  border-radius: 2px;
  background: linear-gradient(180deg, #d8c4a0 0%, #c8b490 50%, #b8a480 100%);
  border: 2px solid #3a2a1a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 3px 6px rgba(0, 0, 0, 0.25);
  position: relative;
}

.sheet td.slot:active {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.25);
}

.sheet tbody tr.alt td.slot {
  background: linear-gradient(180deg, #c8b490 0%, #b8a480 50%, #a89470 100%);
}

.sheet td.slot.has-extra,
.sheet td.slot.editing { vertical-align: top; padding: 4px; }

.sheet td.slot.locked { cursor: default; }

.sheet td.slot.dragover {
  outline: 2px dashed #2a1a0a;
  outline-offset: -4px;
  background: #e8c56a !important;
}

.sheet td.slot.editing {
  outline: 2px solid #1a1410;
  outline-offset: -3px;
  background: #f4f0e8 !important;
}

.cell-text {
  color: #1a1410;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "IBM Plex Mono", "Courier New", monospace;
  padding: 6px;
}

.cell-text a { color: #2a1a0a; text-decoration: underline; }

.cell-text:empty { display: block; min-height: 14px; }

td.editing textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 4px;
  border: 0;
  outline: none;
  resize: vertical;
  background: #f4f0e8;
  color: #1a1410;
  font: bold 13px/1.3 "IBM Plex Mono", "Courier New", monospace;
}

.cell-actions { margin-top: 6px; }

.add-photo {
  height: auto;
  padding: 4px 8px;
  font-size: 11px;
}

.add-photo:disabled { color: #4a3a2a; cursor: progress; }

.add-photo.ghost {
  position: absolute;
  right: 4px;
  bottom: 4px;
  opacity: 0;
  pointer-events: none;
}

td.slot { position: relative; }

td.slot:hover .add-photo.ghost,
td.slot:focus-within .add-photo.ghost {
  opacity: 1;
  pointer-events: auto;
}

.thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.thumb { position: relative; width: 84px; height: 64px; }

.thumb img {
  display: block;
  width: 84px;
  height: 64px;
  object-fit: cover;
  border: 2px solid #3a2a1a;
  border-radius: 2px;
  background: #efe6d4;
}

.thumb-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 24px;
  height: 24px;
  padding: 2px;
  border: 1px solid #c84a4a;
  border-radius: 3px;
  background: #d84a4a;
  color: #fff;
  font-size: 16px;
  line-height: 20px;
  cursor: pointer;
  opacity: 0;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.thumb-x:hover {
  background: #c83a3a;
  border-color: #a83030;
  transform: scale(1.1);
}

.thumb:hover .thumb-x,
.thumb:focus-within .thumb-x,
td.editing .thumb-x { opacity: 1; }

dialog {
  border: 0;
  padding: 0;
  border-radius: 4px;
  background: linear-gradient(180deg, #c9b892 0%, #a89870 100%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

dialog::backdrop { background: rgba(26, 20, 16, 0.7); }

#new-trip-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  border: 3px solid #3a2a1a;
}

#new-trip-dialog h2 {
  margin: 0 0 8px;
  color: #1a1410;
  font-family: "IBM Plex Sans", "Courier New", sans-serif;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1px;
}

#new-trip-dialog p {
  margin: 0 0 14px;
  color: #2a1a0a;
  font-size: 13px;
  font-family: "IBM Plex Mono", "Courier New", monospace;
}

#new-trip-dialog label { margin-bottom: 10px; }

#new-trip-dialog input { width: 100%; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

#lightbox {
  max-width: none;
  max-height: none;
  overflow: visible;
  background: transparent;
  border: 0;
  padding: 0;
}

#lightbox::backdrop { background: rgba(16, 12, 8, 0.9); }

#lightbox img {
  display: block;
  max-width: 92vw;
  max-height: 90vh;
  border: 3px solid #c9a87a;
  border-radius: 2px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

#lightbox-close {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: 2px solid #3a2a1a;
  border-radius: 2px;
  background: linear-gradient(180deg, #e8c56a, #b88830);
  color: #1a1410;
  font-size: 24px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

#lightbox-close:active {
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
  transform: translate(0, 1px);
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  z-index: 30;
  max-width: min(520px, calc(100% - 24px));
  padding: 10px 14px;
  border: 2px solid #3a2a1a;
  border-radius: 2px;
  background: linear-gradient(180deg, #1a1410, #0a0805);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  color: #b8a888;
  font-size: 13px;
  line-height: 1.4;
  transform: translateX(-50%);
  font-family: "IBM Plex Mono", "Courier New", monospace;
  font-weight: 700;
}

/* City and lodging name autocomplete styles */
.city-input-wrapper,
.lodging-name-input-wrapper {
  position: relative;
}

.city-suggestions,
.lodging-name-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 2px solid #8a7850;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.city-suggestion-item,
.lodging-name-suggestion-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #e0e0e0;
  font-size: 14px;
  color: #1a1410;
  transition: background 0.15s;
}

.city-suggestion-item:hover,
.lodging-name-suggestion-item:hover,
.city-suggestion-item.selected,
.lodging-name-suggestion-item.selected {
  background: #f0e8dc;
}

.city-suggestion-item:last-child,
.lodging-name-suggestion-item:last-child {
  border-bottom: none;
}

.city-suggestion-city {
  font-weight: 600;
}

.city-suggestion-region {
  font-size: 12px;
  color: #7a6a5a;
  margin-top: 2px;
}

.lodging-name-suggestion-name {
  font-weight: 600;
}

.lodging-name-suggestion-type {
  font-size: 12px;
  color: #7a6a5a;
  margin-top: 2px;
}

/* Tab styles */
.tabs {
  display: flex;
  gap: 0;
  background: #8a7850;
  border-bottom: 3px solid #6a3a2a;
  padding: 0;
  margin: 0;
}

.tab-btn {
  flex: 1;
  padding: 12px 16px;
  border: none;
  background: #a89878;
  color: #1a1410;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 3px solid #8a7850;
}

.tab-btn:hover {
  background: #b8a888;
}

.tab-btn.active {
  background: #c9b892;
  border-bottom-color: #6a3a2a;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Lodging screen styles */
.lodging-toolbar {
  padding: 16px;
  background: #c9b892;
  border-bottom: 2px solid #8a7850;
}

.lodging-toolbar button {
  width: 100%;
}

.lodging-list-screen {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: #e8dcc8;
  min-height: calc(100vh - 280px);
}

.lodging-list-screen:empty::after {
  content: "No lodging recorded yet.";
  color: #5a4a3a;
  text-align: center;
  padding: 24px;
  grid-column: 1 / -1;
}

/* Lodging dialog styles */
#lodging-edit-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

#lodging-edit-dialog {
  border: 3px solid #6a3a2a;
  border-radius: 4px;
  background: #c9b892;
  color: #1a1410;
  max-width: 600px;
  padding: 24px;
}

#lodging-edit-dialog h2 {
  margin: 0 0 16px 0;
  font-size: 20px;
  color: #6a3a2a;
}

.lodging-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  max-height: 400px;
  overflow-y: auto;
}

.lodging-item {
  background: #e8dcc8;
  border: 2px solid #8a7850;
  border-radius: 4px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.lodging-item:hover {
  background: #f0e8dc;
}

.lodging-item-content {
  flex: 1;
  min-width: 0;
}

.lodging-item-name {
  font-weight: bold;
  font-size: 15px;
  color: #1a1410;
  margin: 0 0 4px 0;
}

.lodging-item-dates {
  font-size: 13px;
  color: #5a4a3a;
  margin: 0;
}

.lodging-item-location {
  font-size: 12px;
  color: #7a6a5a;
  margin: 4px 0 0 0;
}

.lodging-item-type {
  font-size: 12px;
  color: #7a6a5a;
  margin: 4px 0 0 0;
}

#lodging-edit-dialog label {
  display: block;
  margin: 12px 0;
  font-weight: 500;
  color: #1a1410;
}

#lodging-edit-dialog input,
#lodging-edit-dialog select,
#lodging-edit-dialog textarea {
  width: 100%;
  padding: 8px 12px;
  margin-top: 4px;
  border: 2px solid #8a7850;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  background: #f8f6f2;
  color: #1a1410;
  box-sizing: border-box;
}

#lodging-edit-dialog input:focus,
#lodging-edit-dialog select:focus,
#lodging-edit-dialog textarea:focus {
  outline: none;
  border-color: #6a3a2a;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(106, 58, 42, 0.1);
}

#lodging-edit-dialog textarea {
  resize: vertical;
  font-family: "IBM Plex Mono", "Courier New", monospace;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
}

.dialog-actions button {
  padding: 8px 16px;
  border: 2px solid #8a7850;
  border-radius: 4px;
  background: linear-gradient(135deg, #d4a574, #c9985f);
  color: #1a1410;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.dialog-actions button:hover {
  background: linear-gradient(135deg, #deb185, #d4a574);
  transform: scale(1.02);
}

.dialog-actions button.secondary {
  background: #a89878;
  color: #fff;
}

.dialog-actions button.secondary:hover {
  background: #b8a888;
}

#lodging-new-btn {
  width: 100%;
  padding: 10px;
  margin-top: 8px;
}

#lodging-edit-delete {
  background: #a85050 !important;
}

#lodging-edit-delete:hover {
  background: #c86464 !important;
}

/* Admin panel styles */
.admin-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 280px);
  background: #e8dcc8;
}

.admin-tables-list {
  padding: 16px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.admin-table-btn {
  padding: 12px;
  border: 2px solid #8a7850;
  border-radius: 4px;
  background: linear-gradient(180deg, #d4a574, #c9985f);
  color: #1a1410;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: "IBM Plex Sans", "Courier New", sans-serif;
  text-align: center;
}

.admin-table-btn:hover {
  background: linear-gradient(180deg, #deb185, #d4a574);
  transform: scale(1.02);
}

.admin-table-viewer {
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
}

.admin-table-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.admin-table-header h2 {
  margin: 0;
  color: #1a1410;
  font-size: 20px;
  font-weight: 700;
  font-family: "IBM Plex Sans", "Courier New", sans-serif;
}

#admin-back-btn {
  height: 36px;
  padding: 0 14px;
  border: 2px solid #3a2a1a;
  border-radius: 2px;
  background: linear-gradient(180deg, #4a3a2a, #2a1a0a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 3px 6px rgba(0, 0, 0, 0.25);
  color: #d4b896;
  font: bold 12px "IBM Plex Sans", "Courier New", sans-serif;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
}

#admin-back-btn:active {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.25);
  transform: translate(0, 1px);
}

.admin-table-data {
  flex: 1;
  overflow: auto;
  background: #fff;
  border: 2px solid #8a7850;
  border-radius: 4px;
  padding: 0;
}

.admin-data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "IBM Plex Mono", "Courier New", monospace;
  font-size: 13px;
}

.admin-data-table th {
  position: sticky;
  top: 0;
  padding: 8px 12px;
  background: #8a7850;
  color: #fff;
  font-weight: 600;
  text-align: left;
  border-bottom: 2px solid #6a5a3a;
}

.admin-data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #e0e0e0;
  color: #1a1410;
  word-break: break-word;
}

.admin-data-table tbody tr:hover {
  background: #f5f5f5;
}

.admin-data-table tbody tr:nth-child(even) {
  background: #fafaf8;
}

@media (max-width: 800px) {
  .banner {
    flex-wrap: wrap;
    gap: 8px;
  }

  .app-name { font-size: 18px; }

  .calc-display { min-width: 100px; }

  .save-state { margin-left: 0; }

  #lodging-dialog,
  #lodging-edit-dialog {
    max-width: calc(100vw - 32px);
    padding: 16px;
  }

  .lodging-list {
    max-height: 300px;
  }
}
