@import url('https://fonts.googleapis.com/css?family=Roboto');

:root {
  --font-main: 'Roboto', sans-serif;
  --font-mono: 'Courier New', Consolas, monospace;

  --bg-shell: url(/images/quantum-top-candle-bg.png);
  --bg-content: rgba(255, 255, 255, 0.5);
  --bg-param: rgba(255, 255, 255, 0.8);
  --bg-chat: rgba(255, 255, 255, 0.8);
  --bg-message-user: #e3f2fd;
  --bg-message-assistant: #e8f5e9;
  --bg-thinking: #fff3e0;

  --color-primary: #4a90d9;
  --color-primary-hover: #357abd;
  --color-secondary: #6c757d;
  --color-secondary-hover: #5a6268;
  --color-error: #c62828;
  --color-success: #2e7d32;
  --color-warning: #ef6c00;
  --color-info: #1565c0;
  --color-text-main: #333;
  --color-text-muted: #666;
  --color-border: #ccc;

  --shadow-sm: 0 2px 6px rgba(0,0,0,0.12);

  --layout-width-content: 65%;
  --layout-margin-content: calc(100% - 65% + 1em);
  --layout-height-content: calc(100vh - 5em);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

html {
  background: var(--bg-shell) no-repeat center center fixed;
  background-size: cover;
}

body {
  font-family: var(--font-main);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#shell {
  width: 95%;
  margin: 1em 0 0 0;
  min-height: calc(100vh - 2em);
}

#content {
  background-color: var(--bg-content);
  width: var(--layout-width-content);
  margin-left: var(--layout-margin-content);
  margin-right: 1em;
  text-align: left;
  padding: 0;
  display: flex;
  flex-direction: column;
  height: var(--layout-height-content);
}

/* Components */

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  transition: background 0.2s, border-color 0.2s;
  font-family: inherit;
}

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

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

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

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

.btn:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.input-field {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9em;
}

.input-field:focus {
  border-color: var(--color-primary);
  outline: none;
}

/* AI Chat Specifics */

#ai-chat {
  max-width: 800px;
  margin: 0 auto;
}

#model-info-area, #chat-container, #chat-input-area, #status-area, #parameter-section {
  background: var(--bg-param);
  border-radius: 4px;
}

#ai-config {
  margin-bottom: 1em;
  padding: 10px;
}

#parameter-content.collapsed {
  display: none;
}

#toggle-params {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px 12px;
  margin: 8px 0 8px 10px;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--color-text-muted);
  font-family: inherit;
  width: fit-content;
}

#toggle-params:hover {
  border-color: var(--color-primary);
  color: var(--color-text-main);
}

#toggle-params.expanded svg {
  transform: rotate(180deg);
}

#model-info-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
}

#model-info-table table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 0.85em;
}

#model-info-table table th,
#model-info-table table td {
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  text-align: left;
}

#model-info-table table th {
  background: #e3f2fd;
  font-weight: bold;
}

#host-port-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

#host-port-row label {
  font-weight: bold;
  font-size: 0.9em;
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 15px;
}

#chat-messages {
  overflow-y: auto;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fafafa;
  flex: 1;
  min-height: 0;
  margin-bottom: 0;
}

.message {
  margin-bottom: 15px;
  padding: 10px;
  border-radius: 4px;
}

.message.user {
  background: var(--bg-message-user);
  margin-left: 20%;
}

.message.assistant {
  background: var(--bg-message-assistant);
  margin-right: 20%;
}

.message-role {
  font-size: 0.75em;
  font-weight: bold;
  color: var(--color-text-muted);
  margin-bottom: 5px;
}

.message-thinking {
  background: var(--bg-thinking);
  border: 1px solid #ffb74d;
  border-radius: 4px;
  padding: 10px;
  margin-bottom: 10px;
  cursor: pointer;
}

.message-thinking.collapsed .thinking-content {
  display: none;
}

.message-thinking .thinking-content {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #ffe0b2;
  color: #e65100;
  font-size: 0.9em;
}

.message-thinking .thinking-content pre {
  background: #2d2d2d;
  color: #f8f8f2;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 8px 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-thinking .thinking-content code {
  font-family: var(--font-mono);
  background: #fff0d4;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.9em;
}

.message-content {
  line-height: 1.5;
}

.message-content pre {
  background: #2d2d2d;
  color: #f8f8f2;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-content code {
  font-family: var(--font-mono);
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.9em;
}

.message-content pre code {
  background: transparent;
  padding: 0;
}

#chat-input-area {
  display: flex;
  gap: 10px;
  padding: 10px;
  flex-shrink: 0;
}

#user-input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
}

#user-input:disabled {
  background: #eee;
  cursor: not-allowed;
}

#attachment-area {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#attach-btn {
  padding: 10px;
  background: var(--color-secondary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

#attach-btn:hover {
  background: var(--color-secondary-hover);
}

#preview-container {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 120px;
}

#preview-container img {
  max-width: 120px;
  max-height: 80px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}

.preview-remove {
  cursor: pointer;
  color: var(--color-error);
  font-weight: bold;
  font-size: 1.2em;
  line-height: 1;
  padding: 0 2px;
}

.preview-filename {
  font-size: 0.75em;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
}

.user-message-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-attachment img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 6px;
  border: 1px solid #ddd;
}

.user-attachment .file-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.8);
  border: 1px solid #90caf9;
  border-radius: 4px;
  text-decoration: none;
  color: #1565c0;
  font-size: 0.9em;
  cursor: pointer;
}

.download-link {
  display: block;
  color: #1565c0;
  margin: 4px 0;
  word-break: break-all;
}

#status-area {
  margin-top: 0;
  padding: 8px 10px;
  font-size: 0.9em;
  flex-shrink: 0;
}

#status-area table.streaming-status {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 0.85em;
}

#status-area table.streaming-status th,
#status-area table.streaming-status td {
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
}

#status-area table.streaming-status th {
  background: #e3f2fd;
  font-weight: bold;
  position: sticky;
  top: 0;
}

#status-area table.streaming-status td.content-cell {
  white-space: normal;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#status-area table.streaming-status tr#status-row {
  background: #e8f5e9;
}

#status-area.status-info { background: #e3f2fd; color: var(--color-info); }
#status-area.status-success { background: #e8f5e9; color: var(--color-success); }
#status-area.status-warning { background: #fff3e0; color: var(--color-warning); }
#status-area.status-error { background: #ffebee; color: var(--color-error); }

#parameter-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid #ddd;
}

#parameter-section fieldset {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 6px 10px;
  margin: 0;
}

#parameter-section legend {
  font-weight: bold;
  font-size: 0.85em;
  color: var(--color-text-muted);
  padding: 0 6px;
}

#parameter-section label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85em;
  margin-right: 8px;
  margin-bottom: 4px;
  white-space: nowrap;
}

#parameter-section input[type="number"],
#parameter-section input[type="text"],
#parameter-section select {
  padding: 5px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.9em;
  font-family: inherit;
}

#parameter-section input[type="number"] { width: 70px; }
#parameter-section input[type="text"] { width: 160px; }

#parameter-section input:focus,
#parameter-section select:focus {
  border-color: var(--color-primary);
  outline: none;
}

#parameter-section label.has-tooltip {
  position: relative;
  cursor: help;
}

#parameter-section label.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 10;
  display: none;
  padding: 6px 10px;
  font-size: 0.8em;
  font-weight: normal;
  color: var(--color-text-main);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  line-height: 1.4;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

#parameter-section label.has-tooltip:hover::after {
  display: block;
}

#system-message-area label {
  font-weight: bold;
  font-size: 0.9em;
  color: var(--color-text-muted);
}

#system-message {
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  resize: vertical;
  font-family: inherit;
  background: #fafafa;
  flex: 1;
  width: 100%;
  box-sizing: border-box;
}
