/* === CSS Custom Properties === */
:root {
  --bg-primary: #111;
  --bg-secondary: #1a1a1a;
  --bg-item: #1a1a1a;
  --bg-item-hover: #2a2a2a;
  --text-primary: #e0e0e0;
  --text-secondary: #888;
  --color-green: #4caf50;
  --color-white-strike: #666;
  --color-danger: #e57373;
  --color-accent: #e94560;
  --header-height: 48px;
  --item-height: 48px;
  --text-size: 16px;
}

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

html {
  font-size: var(--text-size);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: Roboto, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  touch-action: manipulation;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 4px 0 0;
  background: #333;
  color: #fff;
  min-width: 0;
}

#app-title {
  font-size: 1.25rem;
  font-weight: 400;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  padding: 0 40px;
}

.icon-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:active {
  background: rgba(255,255,255,0.15);
}

.header-actions {
  display: flex;
  align-items: center;
  margin-left: auto;
}

/* === Views === */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  height: calc(100vh - var(--header-height));
}

.view.active {
  display: flex;
}

/* === Item List === */
.item-list {
  flex: 1;
  overflow-y: auto;
}

/* === List Items === */
.list-item {
  display: flex;
  align-items: center;
  height: var(--item-height);
  padding: 0 12px;
  background: transparent;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border-bottom: 1px solid #222;
}

.list-item:active {
  background: #333;
}

.list-item .item-status {
  width: 20px;
  height: 20px;
  margin-right: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.list-item .item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}

.list-item .item-index {
  color: var(--text-secondary);
  font-size: 0.75rem;
  margin-left: 8px;
  flex-shrink: 0;
}

/* Item statuses */
.list-item.status-off .item-name {
  color: var(--text-secondary);
}

.list-item.status-unchecked {
  background: rgba(76, 175, 80, 0.08);
}

.list-item.status-unchecked .item-status {
  color: var(--color-green);
}

.list-item.status-checked {
  background: rgba(255,255,255,0.03);
}

.list-item.status-checked .item-name {
  text-decoration: line-through;
  color: var(--color-white-strike);
}

.list-item.status-checked .item-status {
  color: var(--text-secondary);
}

/* Multi-select mode */
.list-item.multiselect-active {
  background: rgba(233, 69, 96, 0.15) !important;
}

.list-item.multiselect-active .item-status::after {
  content: '✓';
  color: var(--color-accent);
}

/* === Empty State === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-secondary);
  text-align: center;
  padding: 40px 20px;
}

.empty-state p {
  font-size: 1rem;
}

/* === Edit Controls === */
.edit-input-row {
  display: flex;
  gap: 0;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-primary);
  border-bottom: 1px solid #222;
}

.search-input {
  flex: 1;
  height: 48px;
  padding: 0 12px;
  border: none;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
}

.search-input::placeholder {
  color: var(--text-secondary);
}

.add-btn {
  height: 48px;
  padding: 0 20px;
  background: #333;
  color: var(--color-green);
  border: none;
  border-left: 1px solid #222;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
}

.add-btn:active:not(:disabled) {
  background: #444;
}

.add-btn-disabled {
  color: #555;
  cursor: default;
  pointer-events: none;
}

/* === Action Buttons === */
.action-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 0;
  background: #333;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}

.action-btn:active {
  background: #555;
}

.action-btn.danger {
  color: var(--color-danger);
}

/* === Multiselect Bar === */
.multiselect-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #333;
  border-top: 1px solid #222;
}

.multiselect-bar span {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* === Settings === */
.settings-group {
  background: var(--bg-secondary);
  padding: 12px 16px;
  margin-bottom: 0;
}

.settings-group h3 {
  font-size: 0.8rem;
  color: var(--color-green);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding: 8px 16px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #222;
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-row span {
  font-size: 1rem;
}

.setting-row input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--color-green);
}

.setting-row input[type="text"] {
  width: 48px;
  height: 36px;
  text-align: center;
  border: 1px solid #444;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
}

.setting-row select {
  padding: 6px 10px;
  border: 1px solid #444;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
}

/* === Data View === */
.data-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 8px;
}

.export-textarea,
.import-textarea {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  border: none;
  border-bottom: 1px solid #222;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: monospace;
  font-size: 0.85rem;
  resize: vertical;
  margin-bottom: 0;
}

.import-options {
  padding: 12px 0;
  border-bottom: 1px solid #222;
}

.import-options label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.import-options select {
  padding: 6px 10px;
  border: 1px solid #444;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
}

/* === Overlays === */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.overlay > *, .overlay * {
  pointer-events: auto;
}

.menu-panel {
  background: #333;
  width: 80%;
  max-width: 320px;
  overflow: hidden;
}

.menu-back-btn {
  width: 100%;
  padding: 16px;
  background: #222;
  color: var(--text-primary);
  border: none;
  text-align: left;
  font-size: 1rem;
  cursor: pointer;
}

.menu-nav {
  padding: 0;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  border-bottom: 1px solid #2a2a2a;
  color: var(--text-primary);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}

.menu-item:active {
  background: #444;
}

.menu-separator {
  border: none;
  border-top: 1px solid #444;
  margin: 4px 0;
}

/* === Dialog === */
.dialog {
  background: #333;
  padding: 24px;
  width: 85%;
  max-width: 360px;
  text-align: center;
}

#confirm-message {
  margin-bottom: 20px;
  font-size: 1rem;
  line-height: 1.5;
}

.dialog-buttons {
  display: flex;
  gap: 0;
  justify-content: flex-end;
}

.dialog-buttons .action-btn {
  min-width: 70px;
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--color-green);
  font-size: 0.9rem;
  text-transform: uppercase;
  font-weight: 500;
}

.dialog-buttons .action-btn:active {
  background: rgba(76, 175, 80, 0.1);
}

.dialog-buttons .action-btn.danger {
  color: var(--color-danger);
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #555;
  color: #fff;
  padding: 8px 24px;
  font-size: 0.9rem;
  z-index: 300;
  transition: opacity 0.15s;
  max-width: 90%;
  text-align: center;
}

/* === Utility Classes === */
.hidden {
  display: none !important;
}

/* === Responsive === */
@media (max-width: 400px) {
  .action-btn {
    width: 100%;
    text-align: center;
  }
}
