@import url('tokens.css');

/* ==================== */
/* Base Reset           */
/* ==================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  background-color: var(--color-background);
  color: var(--color-text-main);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* ==================== */
/* App Container        */
/* ==================== */
.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ==================== */
/* Screen Layout        */
/* ==================== */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-background);
  transform: translateX(100%);
  transition: transform 0.3s ease-in-out;
  visibility: hidden;
}

.screen.active {
  transform: translateX(0);
  visibility: visible;
}

.screen.prev {
  transform: translateX(-100%);
}

.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  min-height: 56px;
}

.header-title {
  flex: 1;
  font-size: 1.1rem;
  margin: 0;
  text-align: center;
}

.header-spacer {
  width: 70px; /* Match button width for centering */
}

.btn-header {
  background: var(--color-surface);
  border: 2px solid var(--color-primary);
  color: var(--color-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: var(--space-sm) var(--space-md);
  border-radius: 8px;
  min-width: 70px;
  white-space: nowrap;
}

.btn-header:active {
  background: var(--color-primary);
  color: white;
}

.screen-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  -webkit-overflow-scrolling: touch;
}

.screen-content.centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.screen-footer {
  padding: var(--space-md);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

/* ==================== */
/* Login Screen         */
/* ==================== */
#screen-login h1 {
  font-size: 2rem;
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
}

.tagline {
  color: var(--color-text-sub);
  margin-bottom: var(--space-xl);
}

/* ==================== */
/* Buttons              */
/* ==================== */
.btn-primary {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: var(--space-md) var(--space-xl);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.btn-full {
  width: 100%;
}

.btn-large {
  padding: var(--space-lg) var(--space-xl);
  font-size: 1.1rem;
}

.btn-back {
  background: var(--color-surface);
  border: 2px solid var(--color-primary);
  color: var(--color-primary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  padding: var(--space-sm) var(--space-md);
  border-radius: 8px;
  margin-right: var(--space-sm);
}

.btn-back:active {
  background: var(--color-primary);
  color: white;
}

.btn-icon {
  background: var(--color-primary);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==================== */
/* Badge                */
/* ==================== */
.badge {
  background: var(--color-secondary);
  color: white;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.85rem;
  font-weight: 600;
}

.badge.full {
  background: var(--color-primary);
}

/* ==================== */
/* Hint Text            */
/* ==================== */
.hint {
  color: var(--color-text-sub);
  font-size: 0.9rem;
  margin-bottom: var(--space-md);
  text-align: center;
}

/* ==================== */
/* Value Grid (Select)  */
/* ==================== */
.value-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}

.value-chip {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  padding: var(--space-md);
  border-radius: 12px;
  text-align: center;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.value-chip.selected {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.value-chip:active {
  transform: scale(0.95);
}

/* Add Custom */
.add-custom {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
}

.add-custom input {
  flex: 1;
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
}

/* ==================== */
/* Order List           */
/* ==================== */
.order-list {
  list-style: none;
  counter-reset: order-counter;
}

.order-item {
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  cursor: grab;
  transition: box-shadow 0.2s;
}

.order-item::before {
  counter-increment: order-counter;
  content: counter(order-counter);
  background: var(--color-primary);
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  margin-right: var(--space-md);
  flex-shrink: 0;
}

.order-item.sortable-ghost {
  opacity: 0.4;
}

.order-item.sortable-drag {
  box-shadow: var(--shadow-lg);
}

/* ==================== */
/* History Timeline     */
/* ==================== */
.history-timeline {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.history-card {
  background: var(--color-surface);
  border-radius: 12px;
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
}

.history-date {
  font-size: 0.85rem;
  color: var(--color-primary);
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.history-values {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.history-tag {
  background: var(--color-background);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 0.8rem;
  color: var(--color-text-main);
}

.history-tag:first-child {
  background: var(--color-primary);
  color: white;
}

.empty-state {
  text-align: center;
  color: var(--color-text-sub);
  padding: var(--space-xl);
}

/* ==================== */
/* Loading Overlay      */
/* ==================== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==================== */
/* Modal                */
/* ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: var(--color-surface);
  padding: var(--space-lg);
  border-radius: 16px;
  width: 90%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}

.modal-content h3 {
  margin: 0 0 var(--space-md) 0;
  text-align: center;
}

.modal-content textarea {
  width: 100%;
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}

.modal-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.modal-actions button {
  flex: 1;
}

.btn-secondary {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  color: var(--color-text-main);
  padding: var(--space-md) var(--space-lg);
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}

/* History Memo */
.history-memo {
  font-size: 0.85rem;
  color: var(--color-text-sub);
  font-style: italic;
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  background: var(--color-background);
  border-radius: 8px;
}

.history-card {
  cursor: pointer;
}

.history-card:active {
  opacity: 0.8;
}

/* ==================== */
/* Tablet+ Adjustments  */
/* ==================== */
@media (min-width: 600px) {
  .app-container {
    max-width: 480px;
    margin: 0 auto;
    box-shadow: var(--shadow-lg);
  }

  .value-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
