/* =========================================================================
 * PPMailing - UI minimalista
 * Diseño: monocroma, mucho espacio, tipografía sans clara, sin adornos.
 * ========================================================================= */

:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --bg-hover: #f4f4f4;
  --bg-input: #ffffff;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --text: #171717;
  --text-muted: #737373;
  --text-soft: #a3a3a3;
  --accent: #171717;
  --accent-hover: #404040;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --info: #2563eb;
  --info-bg: #eff6ff;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms;
}

a:hover {
  border-bottom-color: var(--text);
}

h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.5em 0;
}

h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

/* ----- Layout ----- */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  border-bottom: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--text);
  color: white;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 700;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: none;
}

.topbar nav a:hover,
.topbar nav a.active {
  background: var(--bg-hover);
  color: var(--text);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
}

.user-chip .role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--text);
  color: white;
  padding: 2px 6px;
  border-radius: 3px;
}

.user-chip .role.user {
  background: var(--text-muted);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
  width: 100%;
  flex: 1;
}

/* ----- Cards ----- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

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

.card-header h2 {
  margin: 0;
}

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  font-weight: 600;
  margin: 24px 0 8px;
}

/* ----- Forms ----- */

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  transition: border-color 120ms, box-shadow 120ms;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(23, 23, 23, 0.06);
}

textarea {
  resize: vertical;
  min-height: 100px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 13px;
}

.field {
  margin-bottom: 16px;
}

.field .hint {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 4px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field-row-3 {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px;
}

/* ----- Buttons ----- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--text);
  color: white;
  border: 1px solid var(--text);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 120ms, border-color 120ms;
  border-bottom: 1px solid var(--text);
}

.btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

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

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

.btn-danger {
  background: white;
  color: var(--error);
  border-color: var(--error);
  border-bottom: 1px solid var(--error);
}

.btn-danger:hover {
  background: var(--error-bg);
  border-bottom-color: var(--error);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

/* ----- Flash messages ----- */

.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid;
}

.flash.success {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
}

.flash.error {
  background: var(--error-bg);
  color: var(--error);
  border-color: var(--error);
}

/* ----- Tables ----- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--bg-hover);
}

.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ----- Status badges ----- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.status-pending {
  color: var(--text-muted);
  background: var(--bg);
}

.badge.status-running {
  color: var(--info);
  background: var(--info-bg);
  border-color: var(--info);
}

.badge.status-running .badge-dot {
  animation: pulse 1.4s infinite;
}

.badge.status-done {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success);
}

.badge.status-error {
  color: var(--error);
  background: var(--error-bg);
  border-color: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ----- Login page ----- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.login-card .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  margin-bottom: 24px;
  font-size: 16px;
}

.login-card h1 {
  font-size: 20px;
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

/* ----- Segment cards (grid) ----- */

.segment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.segment-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 120ms, box-shadow 120ms;
  position: relative;
}

.segment-card:hover {
  border-color: var(--text);
  box-shadow: var(--shadow);
}

.segment-card.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(23, 23, 23, 0.06);
}

.segment-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.segment-card .seg-id {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.segment-card .seg-product {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.segment-card .builtin-tag,
.segment-card .custom-tag {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 3px;
}

.segment-card .builtin-tag {
  background: var(--bg);
  color: var(--text-soft);
}

.segment-card .custom-tag {
  background: var(--info-bg);
  color: var(--info);
}

/* ----- Progress bar ----- */

.progress {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--text);
  transition: width 400ms ease;
}

.progress-fill.error {
  background: var(--error);
}

.progress-fill.done {
  background: var(--success);
}

/* ----- Log viewer ----- */

.log-viewer {
  background: #0a0a0a;
  color: #e5e5e5;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 16px;
  border-radius: var(--radius);
  max-height: 480px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-viewer::-webkit-scrollbar {
  width: 8px;
}

.log-viewer::-webkit-scrollbar-thumb {
  background: #404040;
  border-radius: 4px;
}

/* ----- Stats row ----- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  margin-bottom: 4px;
  font-weight: 600;
}

.stat .value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.stat .value.muted {
  color: var(--text-soft);
}

/* ----- Inline lists ----- */

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.tag {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
}

/* ----- Misc ----- */

.muted {
  color: var(--text-muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
}

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 28px;
  margin-bottom: 8px;
  opacity: 0.4;
}

.toolbar {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar .actions {
  display: flex;
  gap: 8px;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.footer {
  padding: 24px;
  text-align: center;
  color: var(--text-soft);
  font-size: 12px;
}

/* ----- Inline form for delete confirmations ----- */

.inline-form {
  display: inline;
}

/* Link-styled button (used for "salir" in topbar) */
.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms;
}
.link-button:hover {
  border-bottom-color: var(--text);
  color: var(--text);
}

/* Estimate box (cost preview) */
.estimate-box {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  min-height: 60px;
}

/* Role inline select (admin user table) */
.role-select {
  width: auto;
  padding: 4px 8px;
  font-size: 12px;
}

/* Warning progress fill */
.progress-fill.warn {
  background: var(--warning);
}

/* Responsive */

@media (max-width: 720px) {
  .field-row,
  .field-row-3 {
    grid-template-columns: 1fr;
  }
  .topbar {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .container {
    padding: 20px 16px;
  }
  .stat .value { font-size: 18px; }
  th, td { padding: 8px; }
}
