/* Base Styles & Variables */
:root {
  --primary: #1a73e8; /* RaddiPortal-like blue */
  --primary-dark: #1557b0;
  --secondary: #f1f3f4;
  --secondary-hover: #e8eaed;
  --text-main: #202124;
  --text-light: #5f6368;
  --bg-main: #f8f9fa;
  --bg-card: #ffffff;
  --border: #dadce0;
  --error: #d93025;
  --error-bg: #fce8e6;
  --success: #1e8e3e;
  --success-bg: #e6f4ea;
  --warning: #f9ab00;
  --warning-bg: #fef7e0;
  --highlight-bg: #fff8e1; /* For changed cells */
  
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 50px;
  
  --shadow-sm: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
  --shadow-md: 0 1px 3px 0 rgba(60,64,67,0.3), 0 4px 8px 3px rgba(60,64,67,0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-header {
  background-color: var(--primary);
  color: white;
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 600px;
  margin: 0 auto;
}

.app-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.user-info {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-text {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
}

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

.app-main {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 80px; /* Space for bottom action bar */
}

.screen {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
}

.section-header h2 {
  font-size: 18px;
  color: var(--text-main);
}

/* Cards */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

/* Login Screen */
.login-container {
  text-align: center;
  padding: 40px 20px;
  margin-top: 40px;
}

.login-title {
  font-size: 24px;
  color: var(--primary);
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-light);
  margin-bottom: 32px;
}

#google-btn-container {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

/* Typography & Helpers */
.hidden {
  display: none !important;
}

.text-right {
  text-align: right;
}

.info-text {
  color: var(--text-light);
  font-size: 14px;
  margin-top: 12px;
}

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  border-radius: var(--radius-md);
  padding: 12px 20px;
  cursor: pointer;
  border: none;
  transition: background-color 0.2s;
  min-height: 48px; /* Large tap target for mobile */
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-dark);
}

.btn-secondary {
  background-color: var(--secondary);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--secondary-hover);
}

.btn-full {
  width: 100%;
}

.flex-row {
  display: flex;
  gap: 12px;
}

.flex-grow {
  flex: 1;
}

.bottom-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--bg-card);
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  z-index: 10;
  display: flex;
  justify-content: center;
}

@media (min-width: 632px) {
  .bottom-action-bar {
    max-width: 600px;
    margin: 0 auto;
    left: auto;
    right: auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* Tables & Grids */
.table-container {
  padding: 0;
  overflow-x: auto; /* Scroll horizontally if needed */
  -webkit-overflow-scrolling: touch;
}

.supply-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.supply-table th, .supply-table td {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.supply-table th {
  background-color: var(--secondary);
  color: var(--text-main);
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 2;
}

.supply-table .col-pub {
  text-align: left;
  font-weight: 500;
  position: sticky;
  left: 0;
  background-color: var(--bg-card);
  z-index: 3;
  box-shadow: 2px 0 4px -2px rgba(0,0,0,0.1);
}

.supply-table th.col-pub {
  background-color: var(--secondary);
  z-index: 4;
}

/* Editable Table */
.edit-table td:not(.col-pub) {
  padding: 4px; /* Less padding to fit inputs */
}

.cell-bg-amber {
  background-color: var(--highlight-bg) !important;
}

.cell-disabled {
  background-color: var(--secondary) !important;
  color: var(--text-light);
  pointer-events: none;
}

.cell-input {
  width: 48px;
  height: 48px; /* Large tap target */
  text-align: center;
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: #fff;
}

.cell-input:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

.cell-input.changed {
  background-color: var(--highlight-bg);
  border-color: var(--warning);
  font-weight: 600;
}

.cell-input:disabled {
  background-color: transparent;
  border: none;
  color: var(--text-light);
  -webkit-text-fill-color: var(--text-light);
  opacity: 1; /* For iOS */
}

/* Avoid arrows on number inputs */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

/* Form Styles */
.form-card {
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 16px;
}

.row-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
  font-size: 15px;
}

.row-group label {
  margin-bottom: 0;
}

.form-control {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* Prevent iOS zoom */
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  background-color: #fff;
}

.form-control:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

/* Pill Toggle */
.pill-toggle {
  display: inline-flex;
  background-color: var(--secondary);
  border-radius: var(--radius-pill);
  padding: 4px;
}

.pill-btn {
  background: transparent;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
}

.pill-btn.active {
  background-color: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Alerts */
.info-alert {
  display: flex;
  gap: 8px;
  background-color: var(--warning-bg);
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 14px;
  align-items: flex-start;
  margin-top: 16px;
  border-left: 4px solid var(--warning);
}

.info-alert .icon {
  font-size: 16px;
}

/* Preview Screen */
.preview-summary {
  background-color: var(--secondary);
  padding: 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.preview-summary p {
  margin-bottom: 4px;
  font-size: 15px;
}

.preview-summary p:last-child {
  margin-bottom: 0;
}

.simple-table {
  width: 100%;
  border-collapse: collapse;
}

.simple-table th, .simple-table td {
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.simple-table th {
  text-align: left;
  color: var(--text-light);
  font-weight: 500;
}

/* Success Screen */
.success-container {
  text-align: center;
  padding: 32px 20px;
  margin-top: 24px;
}

.success-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.success-container h2 {
  color: var(--success);
  margin-bottom: 8px;
}

.request-id-box {
  background-color: var(--secondary);
  padding: 16px;
  border-radius: var(--radius-md);
  margin: 24px 0;
  border: 1px dashed var(--border);
}

.small-label {
  font-size: 12px;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.request-id-value {
  font-size: 20px;
  font-family: monospace;
  font-weight: 700;
  color: var(--text-main);
}

/* Spinners & Loading States */
.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 0;
}

.spinner-container p {
  margin-top: 12px;
  color: var(--text-light);
  font-weight: 500;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(26, 115, 232, 0.2);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 1s ease-in-out infinite;
}

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

/* Error States */
.error-toast, .error-block {
  background-color: var(--error-bg);
  color: var(--error);
  padding: 12px;
  border-radius: var(--radius-md);
  margin-top: 16px;
  font-size: 14px;
  text-align: center;
  border: 1px solid rgba(217, 48, 37, 0.2);
}

.error-block {
  margin-bottom: 16px;
}

#btn-retry-view, #btn-retry-submit {
  margin-top: 12px;
  min-height: 36px;
  padding: 8px 16px;
  font-size: 14px;
}
