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

:root {
  --primary-color: #007AFF;
  --bg-primary: #FFFFFF;
  --bg-secondary: #F2F2F7;
  --bg-tertiary: #E5E5EA;
  --text-primary: #000000;
  --text-secondary: #3C3C43;
  --text-tertiary: #8E8E93;
  --border-color: #C6C6C8;
  --card-bg: #FFFFFF;
  --header-bg: rgba(249, 249, 249, 0.94);
  --tab-bar-bg: rgba(249, 249, 249, 0.94);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #0A84FF;
    --bg-primary: #000000;
    --bg-secondary: #1C1C1E;
    --bg-tertiary: #2C2C2E;
    --text-primary: #FFFFFF;
    --text-secondary: #EBEBF5;
    --text-tertiary: #8E8E93;
    --border-color: #38383A;
    --card-bg: #1C1C1E;
    --header-bg: rgba(28, 28, 30, 0.94);
    --tab-bar-bg: rgba(28, 28, 30, 0.94);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

/* Views */
.view {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.view.active {
  display: flex;
}

/* Sticky Header */
.sticky-header {
  position: sticky;
  top: 0;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  z-index: 100;
}

.search-container {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

/* Sync Status Indicator */
.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.sync-status:active {
  opacity: 0.7;
}

.sync-status.synced {
  background: rgba(52, 199, 89, 0.1);
  color: #34C759;
}

.sync-status.pending {
  background: rgba(255, 214, 10, 0.1);
  color: #FFD60A;
}

.sync-status.syncing {
  background: rgba(10, 132, 255, 0.1);
  color: #0A84FF;
}

.sync-status.error {
  background: rgba(255, 59, 48, 0.1);
  color: #FF3B30;
}

.sync-icon {
  font-size: 14px;
}

.sync-status.syncing .sync-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#search-input {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 16px;
}

#search-input::placeholder {
  color: var(--text-tertiary);
}

/* Buttons */
.btn-primary {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--primary-color);
  border: none;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 12px;
  width: 100%;
}

.btn-text {
  background: none;
  border: none;
  color: var(--primary-color);
  font-size: 17px;
  cursor: pointer;
  padding: 8px;
}

/* Content */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}

/* Items List */
#items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  position: relative;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 12px;
}

.item-card-content {
  padding: 16px;
  cursor: pointer;
  transition: transform 0.3s ease-out;
  background: var(--card-bg);
  position: relative;
  z-index: 1;
}

.item-card:active .item-card-content {
  transform: scale(0.98);
}

/* Swipe Actions */
.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.swipe-action {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  z-index: 0;
}

.delete-action {
  right: 16px;
  background: #FF3B30;
  color: white;
}

.status-action {
  left: 16px;
  background: #34C759;
  color: white;
}

.item-card.swiped-left .item-card-content {
  transform: translateX(-80px);
}

.item-card.swiped-right .item-card-content {
  transform: translateX(80px);
}

.item-card-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 8px;
}

.item-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.item-type-badge {
  font-size: 20px;
  margin-left: 8px;
}

.item-preview {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-meta {
  font-size: 13px;
  color: var(--text-tertiary);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.task-status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
}

.task-status.todo {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.task-status.doing {
  background: #FFD60A;
  color: #000;
}

.task-status.done {
  background: #34C759;
  color: white;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

/* Tab Bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--tab-bar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  border: none;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.2s;
}

.tab.active {
  color: var(--primary-color);
}

.tab-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.tab-label {
  font-size: 11px;
  font-weight: 500;
}

/* Editor View */
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
}

#editor-title {
  font-size: 17px;
  font-weight: 600;
}

.editor-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: env(safe-area-inset-bottom);
}

.title-input {
  width: 100%;
  border: none;
  background: none;
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding: 8px 0;
}

.title-input::placeholder {
  color: var(--text-tertiary);
}

.task-fields, .link-fields {
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-select, .date-input {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 16px;
}

.url-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 16px;
}

.summary-section, .action-items-section {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 10px;
}

.summary-section strong, .action-items-section strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text-primary);
}

#summary-text {
  color: var(--text-secondary);
  line-height: 1.5;
}

#action-items-list {
  list-style: none;
  padding: 0;
}

#action-items-list li {
  padding: 8px 0;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

#action-items-list li:last-child {
  border-bottom: none;
}

#action-items-list li::before {
  content: "•";
  color: var(--primary-color);
  font-weight: bold;
  margin-right: 8px;
}

/* Quill Editor */
.quill-editor {
  background: var(--card-bg);
  border-radius: 10px;
  min-height: 300px;
}

.ql-container {
  font-size: 16px;
  font-family: inherit;
}

.ql-editor {
  min-height: 250px;
  color: var(--text-primary);
}

.ql-editor.ql-blank::before {
  color: var(--text-tertiary);
}

.ql-toolbar {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

.ql-container {
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  border-color: var(--border-color);
}

.ql-stroke {
  stroke: var(--text-primary);
}

.ql-fill {
  fill: var(--text-primary);
}

.ql-picker-label {
  color: var(--text-primary);
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Modals */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: 20px;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.modal-content p {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.5;
}

.modal-warning {
  color: var(--text-tertiary);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions button {
  flex: 1;
}

.btn-danger {
  background: #FF3B30;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger:active {
  opacity: 0.8;
}

/* Sync Modal Specific */
.sync-modal-content {
  max-width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.sync-status-ok {
  color: #34C759;
  font-weight: 600;
}

.sync-status-info {
  color: var(--primary-color);
}

.sync-status-warning {
  color: #FFD60A;
  font-weight: 600;
}

.sync-status-error {
  color: #FF3B30;
  font-weight: 600;
}

.sync-queue-list {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-tertiary);
  border-radius: 10px;
}

.sync-queue-list h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.sync-queue-list ul {
  list-style: none;
  padding: 0;
}

.sync-queue-list li {
  padding: 8px 0;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
}

.sync-queue-list li:last-child {
  border-bottom: none;
}

.sync-modal-content .btn-primary,
.sync-modal-content .btn-secondary {
  width: 100%;
  margin-top: 12px;
}

/* Theme support */
:root[data-theme="light"] {
  --primary-color: #007AFF;
  --bg-primary: #FFFFFF;
  --bg-secondary: #F2F2F7;
  --bg-tertiary: #E5E5EA;
  --text-primary: #000000;
  --text-secondary: #3C3C43;
  --text-tertiary: #8E8E93;
  --border-color: #C6C6C8;
  --card-bg: #FFFFFF;
  --header-bg: rgba(249, 249, 249, 0.94);
  --tab-bar-bg: rgba(249, 249, 249, 0.94);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

:root[data-theme="dark"] {
  --primary-color: #0A84FF;
  --bg-primary: #000000;
  --bg-secondary: #1C1C1E;
  --bg-tertiary: #2C2C2E;
  --text-primary: #FFFFFF;
  --text-secondary: #EBEBF5;
  --text-tertiary: #8E8E93;
  --border-color: #38383A;
  --card-bg: #1C1C1E;
  --header-bg: rgba(28, 28, 30, 0.94);
  --tab-bar-bg: rgba(28, 28, 30, 0.94);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Header Branding */
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  width: 24px;
  height: 24px;
  color: var(--primary-color);
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

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

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background-color 0.2s;
}

.icon-btn:hover {
  background: var(--bg-tertiary);
}

.icon-btn:active {
  opacity: 0.7;
}

/* Quick Add */
.quick-add-section {
  margin-bottom: 16px;
}

.quick-add-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.quick-add-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 15px;
}

.quick-add-input::placeholder {
  color: var(--text-tertiary);
}

.quick-add-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.quick-add-btn:active {
  opacity: 0.8;
}

/* Task Filters */
.task-filters {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-chip {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-primary);
  border-radius: 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.filter-chip:hover {
  background: var(--bg-tertiary);
}

.filter-chip.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Pinned Section */
.section-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 16px 16px 8px;
  margin: 0;
}

.pinned-section {
  margin-bottom: 24px;
}

.pin-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  z-index: 2;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.pin-btn:hover,
.pin-btn.pinned {
  opacity: 1;
}

.item-card {
  position: relative;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 80px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--card-bg);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  pointer-events: auto;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-message {
  font-size: 14px;
  font-weight: 500;
}

.toast-actions {
  display: flex;
  gap: 8px;
}

.toast-action-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.toast-action-btn:active {
  opacity: 0.8;
}

/* Search highlight */
mark {
  background: rgba(255, 214, 10, 0.4);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

/* Settings modal specific */
.settings-section {
  margin: 16px 0;
}

.settings-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.settings-section p {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.danger-zone {
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
  margin-top: 16px;
}

.danger-zone h3 {
  color: #FF3B30;
}

.file-input-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
  width: 100%;
}

.file-input-wrapper input[type=file] {
  position: absolute;
  left: -9999px;
}

.file-input-btn {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}

.reset-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 15px;
  margin-bottom: 12px;
}

/* Draft restore prompt */
.draft-prompt {
  background: rgba(255, 214, 10, 0.1);
  border: 1px solid rgba(255, 214, 10, 0.3);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  font-size: 14px;
}

.draft-prompt-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.draft-prompt-actions button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.draft-prompt-actions button:first-child {
  background: var(--primary-color);
  color: white;
}

.draft-prompt-actions button:last-child {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
