:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #263449;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #6366f1;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.app-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sync-pill {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.sync-pill.is-synced {
  border-color: rgba(16, 185, 129, 0.45);
  color: #6ee7b7;
}

.sync-pill.is-pending {
  border-color: rgba(245, 158, 11, 0.45);
  color: #fcd34d;
}

.sync-pill.is-error {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-ghost {
  background: transparent;
}

.btn-icon {
  min-width: 40px;
  padding: 8px;
}

.btn-warning-ghost {
  background: transparent;
  border-color: rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-block {
  width: 100%;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--border);
  font-size: 0.75rem;
}

/* Counter Grid */
.main-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.counter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.counter-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--card-accent, var(--accent));
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none;
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.counter-card.is-tapped {
  transform: scale(0.96);
  background: var(--surface-hover);
}

.card-tap-area {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: 152px;
  padding: 14px;
  padding-right: 46px;
  border: 0;
  background: transparent;
  text-align: left;
}

.card-menu-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
}

.card-menu-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.card-icon {
  font-size: 1.85rem;
  line-height: 1;
  margin-bottom: 8px;
}

.card-name {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 8px;
  word-break: break-word;
}

.card-today {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: auto;
}

.card-today-num {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.card-unit {
  font-size: 0.8rem;
  color: var(--muted);
}

.card-meta {
  margin-top: 6px;
  font-size: 0.76rem;
  color: var(--muted);
}

.card-goal-track {
  width: 100%;
  height: 4px;
  margin-top: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  overflow: hidden;
}

.card-goal-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--card-accent, var(--accent));
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 1.1rem;
  font-weight: 700;
}

.empty-subtitle {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.92rem;
}

.empty-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* Bottom Undo / Note Toast */
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #0b1220;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.toast[hidden] {
  display: none;
}

.toast-message {
  font-size: 0.92rem;
  font-weight: 600;
}

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

.btn-toast {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-toast-undo {
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

/* Dialogs & Bottom Sheets */
dialog.sheet-dialog {
  width: min(520px, 100vw);
  max-width: 100vw;
  max-height: 90dvh;
  margin: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
}

dialog.sheet-dialog::backdrop {
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(3px);
}

@media (max-width: 600px) {
  dialog.sheet-dialog {
    margin: auto 0 0 0;
    width: 100vw;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-title {
  margin: 0;
  font-size: 1.15rem;
}

.detail-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-icon {
  font-size: 1.9rem;
}

.detail-stats {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.dialog-section {
  padding: 12px 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  font-size: 0.88rem;
  font-weight: 600;
}

.field-row,
.input-row {
  display: flex;
  gap: 10px;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="password"],
input[type="date"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

input[type="color"] {
  width: 100%;
  height: 44px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.chip-row,
.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.85rem;
  font-weight: 600;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.25);
}

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

.history-list,
.archive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item,
.archive-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-main {
  font-weight: 700;
  font-size: 0.92rem;
}

.history-sub {
  font-size: 0.78rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.archive-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.helper-text,
.confirm-text,
.empty-archive {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.dialog-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
