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

body {
  display: flex;
  flex-direction: column;
  color: #201f1e;
  background: #faf9f8;
}

.app-header {
  flex: 0 0 auto;
  padding: 12px 16px;
  border-bottom: 1px solid #edebe9;
  background: #fff;
}

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

.workbook-name {
  margin: 4px 0 0 0;
  font-size: 11px;
  color: #605e5c;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workbook-name:empty::before {
  content: "(loading workbook…)";
  color: #a19f9d;
}

.tabs {
  flex: 0 0 auto;
  display: flex;
  background: #fff;
  border-bottom: 1px solid #edebe9;
}

.tab {
  font: inherit;
  font-size: 13px;
  padding: 8px 16px;
  background: transparent;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: #605e5c;
}

.tab:hover {
  background: #f3f2f1;
  color: #201f1e;
}

.tab.active {
  border-bottom-color: #0078d4;
  color: #201f1e;
  font-weight: 600;
}

.app-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tab-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.tab-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.tab-panel[hidden] {
  display: none;
}

.rules-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #faf9f8;
  border-bottom: 1px solid #edebe9;
  flex-wrap: wrap;
}

.rules-toolbar-persona {
  background: #fff;
}

.rules-toolbar-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #323130;
  flex: 1 1 auto;
  min-width: 0;
}

.rules-scope,
.rules-persona {
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid #d1d1d1;
  border-radius: 3px;
  background: #fff;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
}

.btn {
  font: inherit;
  font-size: 12px;
  padding: 5px 12px;
  background: #fff;
  border: 1px solid #d1d1d1;
  border-radius: 3px;
  cursor: pointer;
  color: inherit;
}

.btn:hover {
  background: #f3f2f1;
  border-color: #b3b0ad;
}

.btn-primary {
  background: #0078d4;
  border-color: #0078d4;
  color: #fff;
}

.btn-primary:hover {
  background: #106ebe;
  border-color: #106ebe;
}

.rules-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rules-empty {
  margin: 0;
  text-align: center;
  color: #605e5c;
  padding: 24px 16px;
  font-size: 12px;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #d1d1d1;
  border-radius: 4px;
  background: #fff;
}

.rule-item.dragging {
  opacity: 0.4;
}

.rule-item.not-in-persona {
  opacity: 0.45;
  background: #faf9f8;
}

.rule-item.not-in-persona .rule-name {
  font-weight: 500;
}

.rule-item.drop-before {
  box-shadow: 0 -2px 0 0 #0078d4;
}

.rule-item.drop-after {
  box-shadow: 0 2px 0 0 #0078d4;
}

.rule-handle {
  cursor: grab;
  color: #a19f9d;
  user-select: none;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}

.rule-handle:active {
  cursor: grabbing;
}

.rule-toggle {
  margin: 0;
  flex: 0 0 auto;
}

.rule-body {
  flex: 1 1 auto;
  min-width: 0;
}

.rule-name {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-desc {
  font-size: 11px;
  color: #605e5c;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-source {
  font-size: 10px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 10px;
  letter-spacing: 0.04em;
  flex: 0 0 auto;
}

.rule-source--system {
  background: #deecf9;
  color: #004578;
}

.rule-source--user {
  background: #edebe9;
  color: #605e5c;
}

.sev-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.sev-dot--error {
  background: #a4262c;
}

.sev-dot--warning {
  background: #d29200;
}

.sev-dot--info {
  background: #0078d4;
}

.rule-action-btn {
  font: inherit;
  font-size: 11px;
  padding: 3px 8px;
  background: #fff;
  border: 1px solid #d1d1d1;
  border-radius: 3px;
  cursor: pointer;
  color: inherit;
}

.rule-action-btn:hover {
  background: #f3f2f1;
}

.rule-action-btn--danger {
  color: #a4262c;
  border-color: #d1d1d1;
}

.rule-action-btn--danger:hover {
  background: #fde7e9;
  border-color: #a4262c;
}

.action-list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  overflow-y: auto;
}

.action-button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #d1d1d1;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.action-button:hover {
  background: #f3f2f1;
  border-color: #b3b0ad;
}

.action-button:active {
  background: #edebe9;
}

.action-button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.action-label {
  font-weight: 600;
}

.action-desc {
  font-size: 12px;
  color: #605e5c;
  margin-top: 2px;
}

.feed-section {
  flex: 0 0 35%;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #edebe9;
  background: #fff;
  overflow: hidden;
}

.feed-header {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  color: #605e5c;
  background: #faf9f8;
  border-bottom: 1px solid #edebe9;
}

.feed-clear {
  background: transparent;
  border: 1px solid transparent;
  padding: 2px 8px;
  font: inherit;
  font-size: 11px;
  color: #605e5c;
  cursor: pointer;
  border-radius: 3px;
}

.feed-clear:hover {
  background: #f3f2f1;
  border-color: #d1d1d1;
  color: #201f1e;
}

.feed {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 12px;
  font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: 11px;
  line-height: 1.5;
}

.feed-entry {
  white-space: pre-wrap;
  word-break: break-word;
}

.feed-time {
  color: #a19f9d;
  margin-right: 8px;
}

.feed-entry--info .feed-msg {
  color: #323130;
}

.feed-entry--success .feed-msg {
  color: #107c10;
}

.feed-entry--error .feed-msg {
  color: #a4262c;
}

/* ---------- Sign-in panel (M4) ---------- */

.auth-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5em;
  font-size: 0.85em;
  color: #555;
  padding: 0.25em 1em;
}

.auth-email {
  font-style: italic;
}

.btn-link {
  background: none;
  border: none;
  color: #0066cc;
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

.btn-link:hover {
  color: #004080;
}

.signin-panel {
  padding: 2em 1.5em;
  max-width: 360px;
  margin: 1em auto;
  text-align: left;
}

.signin-panel h2 {
  margin-top: 0;
  font-size: 1.15em;
}

.signin-help {
  color: #666;
  font-size: 0.9em;
  margin-bottom: 1.25em;
}

.signin-form {
  display: flex;
  flex-direction: column;
  gap: 0.75em;
  margin-bottom: 1em;
}

.signin-form input {
  padding: 0.5em 0.75em;
  font-size: 1em;
  border: 1px solid #ccc;
  border-radius: 3px;
}

.signin-form input:focus {
  outline: 2px solid #0066cc;
  outline-offset: -2px;
}

.signin-form input:disabled {
  background: #f4f4f4;
  color: #999;
}

#signin-code {
  font-family: monospace;
  font-size: 1.25em;
  letter-spacing: 0.25em;
  text-align: center;
}

.signin-code-help {
  font-size: 0.9em;
  color: #555;
}

.signin-error {
  color: #a4262c;
  font-size: 0.9em;
  margin-top: 0.5em;
}

.signin-mode {
  margin-top: 1.5em;
  padding: 0.5em 0.75em;
  background: #fff8e1;
  border-left: 3px solid #f9a825;
  font-size: 0.8em;
  color: #6f4f00;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
