/* Reset and base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.5;
}

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

.error {
  color: #d32f2f;
  font-size: 0.9rem;
}

/* Views */
.view {
  min-height: 100vh;
}

/* Login View */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a237e 0%, #0d47a1 100%);
}

.login-container {
  background: white;
  padding: 3rem;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.login-container h1 {
  color: #1a237e;
  margin-bottom: 0.5rem;
}

.login-container .subtitle {
  color: #666;
  margin-bottom: 2rem;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#login-form input {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

#login-form button {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  background: #1a237e;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

#login-form button:hover {
  background: #0d47a1;
}

#login-error {
  margin-top: 1rem;
}

/* Header */
header {
  background: #1a237e;
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-left h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.header-left .org-name {
  opacity: 0.8;
  font-size: 0.9rem;
  margin-left: 0.5rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.stats {
  font-size: 0.9rem;
  opacity: 0.9;
}

.stats .blockers {
  background: #ff5252;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  margin-left: 0.5rem;
}

nav {
  display: flex;
  gap: 0.5rem;
}

.nav-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav-btn.active {
  background: white;
  color: #1a237e;
}

.logout-btn {
  padding: 0.5rem 1rem;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.app-version {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  margin-left: 0.5rem;
  font-family: monospace;
}

/* Content Views */
.content-view {
  height: calc(100vh - 70px);
  overflow-y: auto;
}

/* Integrated Chat Panel */
.chat-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 40px);
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  transition: all 0.3s ease;
}

.chat-panel.collapsed {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1a237e;
  box-shadow: 0 4px 12px rgba(26, 35, 126, 0.4);
}

.chat-panel.collapsed:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(26, 35, 126, 0.5);
}

.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #1a237e;
  color: white;
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  user-select: none;
}

.chat-panel.collapsed .chat-panel-header {
  justify-content: center;
  padding: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
}

.chat-panel-header:hover {
  background: #0d47a1;
}

.chat-panel.collapsed .chat-panel-header:hover {
  background: #1a237e;
}

.chat-header-text {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-panel.collapsed .chat-header-text {
  display: none;
}

.chat-icon {
  font-size: 1.2rem;
}

.chat-panel.collapsed .chat-icon {
  display: none;
}

.chat-minimized-icon {
  display: none;
  font-size: 1.5rem;
  font-weight: bold;
}

.chat-panel.collapsed .chat-minimized-icon {
  display: block;
}

.chat-toggle-icon {
  margin-left: auto;
  font-size: 0.8rem;
  transition: transform 0.3s ease;
}

.chat-panel.collapsed .chat-toggle-icon {
  display: none;
}

.chat-panel-body {
  display: flex;
  flex-direction: column;
  height: 350px;
}

.chat-panel.collapsed .chat-panel-body {
  display: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 80%;
  padding: 1rem;
  border-radius: 8px;
}

.message.user {
  align-self: flex-end;
  background: #1a237e;
  color: white;
}

.message.assistant {
  align-self: flex-start;
  background: white;
  border: 1px solid #ddd;
}

.message-content {
  white-space: pre-wrap;
}

.message .saved-badge {
  display: inline-block;
  background: #4caf50;
  color: white;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  margin-top: 0.5rem;
}

.chat-input-container {
  display: flex;
  padding: 0.75rem;
  background: #f5f5f5;
  border-top: 1px solid #ddd;
  gap: 0.5rem;
}

#chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

#chat-send {
  padding: 0.75rem 1.5rem;
  background: #1a237e;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#chat-send:hover {
  background: #0d47a1;
}

#chat-send:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Thinking indicator */
.message.thinking .message-content {
  background: #e8e8e8;
}

.thinking-dots {
  display: inline-flex;
  gap: 2px;
}

.thinking-dots span {
  animation: thinking 1.4s infinite;
  font-size: 1.5em;
  line-height: 0.5;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes thinking {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* Form View */
#form-view {
  display: flex;
}

.form-sidebar {
  width: 250px;
  background: white;
  border-right: 1px solid #ddd;
  padding: 1rem;
  overflow-y: auto;
}

.form-sidebar h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 1rem;
}

#section-nav {
  list-style: none;
}

#section-nav li {
  margin-bottom: 0.5rem;
}

#section-nav a {
  display: block;
  padding: 0.5rem;
  color: #333;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.9rem;
}

#section-nav a:hover {
  background: #f0f0f0;
}

#section-nav a.active {
  background: #e3f2fd;
  color: #1a237e;
}

#section-nav .completion {
  font-size: 0.8rem;
  color: #666;
  margin-left: 0.5rem;
}

.form-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.form-section {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.form-section h2 {
  font-size: 1.25rem;
  color: #1a237e;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e3f2fd;
}

.form-field {
  margin-bottom: 1.25rem;
}

.form-field label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.form-field .required {
  color: #d32f2f;
  margin-left: 0.25rem;
}

.form-field .lookup-link {
  font-size: 0.85rem;
  font-weight: normal;
  margin-left: 0.5rem;
  color: #1a237e;
  text-decoration: none;
  background: #e3f2fd;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.form-field .lookup-link:hover {
  background: #bbdefb;
  text-decoration: underline;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #ffffff !important;
  color: #333 !important;
  color-scheme: light;
}

.form-field textarea {
  min-height: 100px;
  resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: #1a237e;
}

.form-field .hint {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0.25rem;
}

.form-field.filled input,
.form-field.filled select,
.form-field.filled textarea {
  border-color: #4caf50;
  background-color: #f1f8e9 !important;
}

/* Checkbox group for multiselect fields */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #ffffff;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.25rem 0;
  font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  margin-top: 0.2rem;
  cursor: pointer;
  accent-color: #1a237e;
}

.checkbox-label span {
  flex: 1;
  line-height: 1.4;
}

.checkbox-label:hover {
  background-color: #f5f5f5;
  margin: 0 -0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.form-field.filled .checkbox-group {
  border-color: #4caf50;
  background-color: #f1f8e9;
}

/* Financial table styling */
.financial-field {
  margin-bottom: 2rem;
}

.financial-field > label {
  font-size: 1.1rem;
  color: #1a237e;
  margin-bottom: 1rem;
  display: block;
}

.financial-table {
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
}

.financial-section {
  padding: 1rem;
  border-bottom: 1px solid #eee;
}

.financial-section:last-child {
  border-bottom: none;
}

.financial-section h4 {
  font-size: 0.9rem;
  color: #1a237e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e3f2fd;
}

.financial-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.4rem 0;
}

.financial-row label {
  flex: 1;
  font-size: 0.9rem;
  color: #555;
  font-weight: normal;
}

.financial-row input {
  width: 150px;
  padding: 0.4rem 0.6rem;
  text-align: right;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.9rem;
}

.financial-row input:focus {
  outline: none;
  border-color: #1a237e;
  background-color: #fff;
}

.financial-row input:not(:placeholder-shown) {
  background-color: #f1f8e9;
  border-color: #4caf50;
}

/* Save controls in header */
.save-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.save-status {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

.save-status.saving {
  color: #ffb74d;
}

.save-status.saved {
  color: #81c784;
}

.save-status.error {
  color: #ef5350;
}

.save-btn {
  padding: 0.4rem 1rem;
  background: #4caf50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.save-btn:hover {
  background: #43a047;
}

/* Export View */
#export-view {
  overflow-y: auto !important;
  height: calc(100vh - 70px);
}

.export-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem;
  padding-bottom: 4rem;
}

.export-container h2 {
  color: #1a237e;
  margin-bottom: 0.5rem;
}

.export-info {
  color: #666;
  margin-bottom: 1.5rem;
}

.export-info a {
  color: #1a237e;
}

.export-actions {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
}

.export-actions button {
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.export-actions button:first-child {
  background: #1a237e;
  color: white;
  border: none;
}

.export-actions button.secondary {
  background: white;
  color: #1a237e;
  border: 1px solid #1a237e;
}

#export-content {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.export-section {
  margin-bottom: 2rem;
  page-break-inside: avoid;
}

.export-section h3 {
  color: #1a237e;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #ddd;
}

.export-field {
  display: flex;
  margin-bottom: 0.75rem;
  padding: 0.5rem;
  background: #f9f9f9;
  border-radius: 4px;
}

.export-field .field-label {
  flex: 0 0 40%;
  font-weight: 500;
  color: #666;
}

.export-field .field-value {
  flex: 1;
}

.export-field.unfilled {
  background: #fff3e0;
}

.export-field.unfilled .field-value {
  color: #e65100;
  font-style: italic;
}

/* Array field styling */
.array-field {
  margin-bottom: 2rem;
}

.array-field > label {
  font-size: 1.1rem;
  color: #1a237e;
  margin-bottom: 0.5rem;
  display: block;
}

.array-items-container {
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fafafa;
  margin-bottom: 0.75rem;
}

.empty-array-message {
  padding: 1.5rem;
  text-align: center;
  color: #888;
  font-style: italic;
}

.array-item {
  padding: 1rem;
  border-bottom: 1px solid #e0e0e0;
  background: white;
}

.array-item:first-child {
  border-radius: 8px 8px 0 0;
}

.array-item:last-child {
  border-bottom: none;
  border-radius: 0 0 8px 8px;
}

.array-item:only-child {
  border-radius: 8px;
}

.array-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e3f2fd;
}

.array-item-number {
  font-weight: 600;
  color: #1a237e;
  font-size: 0.9rem;
}

.remove-array-item-btn {
  background: #ffebee;
  color: #d32f2f;
  border: 1px solid #ffcdd2;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s;
}

.remove-array-item-btn:hover {
  background: #ffcdd2;
  border-color: #ef9a9a;
}

.array-item-fields {
  display: grid;
  gap: 0.75rem;
}

.array-sub-field {
  margin-bottom: 0.5rem;
}

.array-sub-field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: #555;
  margin-bottom: 0.25rem;
}

.array-sub-field input,
.array-sub-field textarea,
.array-sub-field select {
  width: 100%;
  padding: 0.5rem;
  font-size: 0.95rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #ffffff;
}

.array-sub-field textarea {
  min-height: 60px;
  resize: vertical;
}

.array-sub-field input:focus,
.array-sub-field textarea:focus,
.array-sub-field select:focus {
  outline: none;
  border-color: #1a237e;
}

.add-array-item-btn {
  display: block;
  width: 100%;
  padding: 0.75rem;
  background: #e3f2fd;
  color: #1a237e;
  border: 2px dashed #90caf9;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.add-array-item-btn:hover {
  background: #bbdefb;
  border-color: #1a237e;
}

/* Nested object field styling (for complex sub-fields like funding_and_expenses) */
.nested-object-field {
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 0.75rem;
}

.nested-field {
  margin-bottom: 0.5rem;
}

.nested-field:last-child {
  margin-bottom: 0;
}

.nested-field label {
  font-size: 0.8rem;
  color: #666;
}

.nested-field input,
.nested-field textarea {
  margin-top: 0.25rem;
}

/* Responsive */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  #form-view {
    flex-direction: column;
  }

  .form-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #ddd;
  }

  #section-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #section-nav li {
    margin-bottom: 0;
  }

  .message {
    max-width: 95%;
  }
}

/* Print styles */
@media print {
  header, .chat-input-container, .form-sidebar, .export-actions, nav {
    display: none;
  }

  .content-view {
    height: auto;
    overflow: visible;
  }

  #export-content {
    box-shadow: none;
    padding: 0;
  }

  .export-section {
    page-break-inside: avoid;
  }
}
