/* Apple-style CSS for Driver Invoice App */

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

:root {
  --primary: #007AFF;
  --primary-light: #5AC8FA;
  --success: #34C759;
  --warning: #FF9500;
  --danger: #FF3B30;
  --gray: #8E8E93;
  --gray-light: #AEAEB2;
  --gray-lighter: #E5E5EA;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #000000;
  --text-secondary: #8E8E93;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  padding-bottom: 120px;
}

/* Header */
.header {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--gray-lighter);
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}

/* Input Section */
.input-section {
  padding: 16px;
}

.input-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

textarea {
  width: 100%;
  height: 140px;
  border: none;
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: background 0.2s;
}

textarea:focus {
  background: var(--gray-lighter);
}

textarea::placeholder {
  color: var(--gray-light);
  font-size: 14px;
}

.input-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: #0056B3;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
}

.btn-secondary:active {
  background: var(--gray-lighter);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:active {
  background: #2A9D3F;
}

.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-warning:active {
  background: #CC7700;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  font-size: 16px;
}

.btn-icon-small {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--gray);
  cursor: pointer;
  padding: 4px 8px;
}

/* Preview Section */
.preview-section {
  padding: 0 16px 16px;
}

.card {
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.card-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--gray-lighter);
}

.preview-content {
  padding: 16px;
}

.preview-item {
  display: flex;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-lighter);
}

.preview-item:last-child {
  border-bottom: none;
}

.preview-label {
  width: 90px;
  font-size: 14px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.preview-value {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  word-break: break-all;
}

/* History Section */
.history-section {
  padding: 16px;
}

.filter-tabs {
  display: flex;
  background: var(--bg);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.record-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

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

.record-card.selected {
  box-shadow: 0 0 0 3px var(--primary);
}

.record-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.record-date {
  font-size: 15px;
  font-weight: 600;
}

.record-status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
}

.status-uninvoiced {
  background: rgba(0, 122, 255, 0.15);
  color: var(--primary);
}

.status-invoiced {
  background: rgba(52, 199, 89, 0.15);
  color: var(--success);
}

.record-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.record-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.record-label {
  color: var(--text-secondary);
}

.record-value {
  font-weight: 500;
  text-align: right;
}

.record-checkbox {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--gray-lighter);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.record-card.selected .record-checkbox {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

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

.empty-state p {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state small {
  font-size: 14px;
}

/* Action Bar */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--gray-lighter);
  z-index: 100;
}

.action-bar.hidden {
  display: none;
}

.action-info {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.action-buttons {
  display: flex;
  gap: 10px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--card);
  width: 100%;
  max-width: 430px;
  max-height: 80vh;
  border-radius: 20px 20px 0 0;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-lighter);
  font-size: 17px;
  font-weight: 600;
}

.invoice-content {
  padding: 20px;
  max-height: 50vh;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.8;
  white-space: pre-wrap;
  background: var(--bg);
  margin: 16px;
  border-radius: 12px;
}

.modal-footer {
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--gray-lighter);
}

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

.loading-overlay.hidden {
  display: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-lighter);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

.loading-overlay p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 12px 24px;
  border-radius: 25px;
  font-size: 14px;
  z-index: 400;
  animation: fadeInUp 0.3s ease;
}

.toast.hidden {
  display: none;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Hidden */
.hidden {
  display: none !important;
}

/* API Key Setup */
.api-key-section {
  padding: 16px;
}

.api-key-card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
}

.api-key-input {
  width: 100%;
  padding: 14px;
  border: none;
  background: var(--bg);
  border-radius: 12px;
  font-size: 15px;
  outline: none;
  font-family: monospace;
}

/* Checkbox style for records */
.record-card {
  position: relative;
}

.record-checkbox {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--gray-lighter);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.record-card.selected .record-checkbox {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}