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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  background: #f0f2f5;
  color: #1a1a2e;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

header {
  background: #1565c0;
  color: #fff;
  padding: 10px 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
}

.btn-logout {
  padding: 4px 12px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}

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

/* ── Toolbar ─────────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid #dde3ec;
  flex-shrink: 0;
}

.toolbar-sep { width: 1px; height: 24px; background: #dde3ec; margin: 0 4px; }

.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.entry-count { color: #666; font-size: 12px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  padding: 6px 14px;
  border: 1px solid #c8d0dc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: #333;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: #f5f7fa; border-color: #aab; }
.btn:active:not(:disabled) { background: #eaecf0; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: #1565c0; color: #fff; border-color: #1565c0; }
.btn-primary:hover:not(:disabled) { background: #1976d2; border-color: #1976d2; }

.btn-success { background: #2e7d32; color: #fff; border-color: #2e7d32; }
.btn-success:hover:not(:disabled) { background: #388e3c; border-color: #388e3c; }

.btn-danger { background: #c62828; color: #fff; border-color: #c62828; }
.btn-danger:hover:not(:disabled) { background: #d32f2f; border-color: #d32f2f; }

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

/* ── Table ────────────────────────────────────────────────────────────────── */

.table-container {
  flex: 1;
  overflow: auto;
  background: #fff;
  border-bottom: 1px solid #dde3ec;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead {
  position: sticky;
  top: 0;
  background: #e8edf4;
  z-index: 1;
}

th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: #4a5568;
  border-bottom: 2px solid #c9d2e0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

td {
  padding: 7px 10px;
  border-bottom: 1px solid #edf0f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

tr:hover td { background: rgba(21, 101, 192, 0.05); }

tr.selected td { background: #e3f0fd !important; }

tr.status-CREATED td { background: #f1f8f1; }
tr.status-ERROR td { background: #fff5f5; }
tr.status-DELETED td, tr.status-USER_EXPIRED td { background: #f9f9f9; color: #999; }
tr.status-REVOKED td { background: #fff8f0; }
tr.status-UPDATED td { background: #f0f8ff; }

.empty-row td { text-align: center; color: #999; padding: 40px; }

/* Column widths */
.col-check { width: 36px; }
th:nth-child(2), td:nth-child(2) { min-width: 130px; }
th:nth-child(3), td:nth-child(3) { min-width: 110px; }
th:nth-child(4), td:nth-child(4) { min-width: 160px; }
th:nth-child(5), td:nth-child(5) { min-width: 120px; }
th:nth-child(6), td:nth-child(6) { min-width: 110px; }
th:nth-child(7), td:nth-child(7) { min-width: 90px; }
th:nth-child(8), td:nth-child(8) { min-width: 100px; }
th:nth-child(9), td:nth-child(9) { min-width: 90px; }
th:nth-child(10), td:nth-child(10) { min-width: 110px; }
th:nth-child(11), td:nth-child(11) { min-width: 200px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-op-create  { background: #dbeafe; color: #1d4ed8; }
.badge-op-update  { background: #fef3c7; color: #92400e; }
.badge-op-alter   { background: #fef3c7; color: #92400e; }
.badge-op-delete  { background: #fee2e2; color: #991b1b; }
.badge-op-revoke  { background: #e5e7eb; color: #374151; }

.badge-st-CREATED      { background: #dcfce7; color: #166534; }
.badge-st-ERROR        { background: #fee2e2; color: #991b1b; }
.badge-st-DELETED      { background: #e5e7eb; color: #374151; }
.badge-st-USER_EXPIRED { background: #e5e7eb; color: #374151; }
.badge-st-REVOKED      { background: #fef3c7; color: #92400e; }
.badge-st-UPDATED      { background: #dbeafe; color: #1d4ed8; }

.badge-db-mysql    { background: #fff3cd; color: #856404; }
.badge-db-postgres { background: #cff4fc; color: #055160; }

/* ── Log Panel ───────────────────────────────────────────────────────────── */

.log-panel {
  flex-shrink: 0;
  background: #1a1a2e;
  color: #e2e8f0;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 14px;
  cursor: pointer;
  background: #16213e;
  user-select: none;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
}

.log-header:hover { background: #1e2a45; }

.log-body {
  height: 120px;
  overflow-y: auto;
  padding: 6px 14px;
}

.log-body.collapsed { height: 0; overflow: hidden; }

.log-line { padding: 1px 0; line-height: 1.5; }
.log-line.log-error { color: #f87171; }
.log-line.log-success { color: #4ade80; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #c0d0e8;
  border-top-color: #1565c0;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.hidden { display: none !important; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 600px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-wide { width: 860px; }
.modal-sm   { width: 380px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e9f0;
}

.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: #666;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  border-radius: 4px;
}

.modal-close:hover { background: #f0f2f5; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-body h3 {
  font-size: 13px;
  font-weight: 600;
  color: #4a5568;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e5e9f0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid #e5e9f0;
}

/* ── Form ────────────────────────────────────────────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: #4a5568;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 7px 10px;
  border: 1px solid #c8d0dc;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  color: #1a1a2e;
  background: #fff;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #1565c0;
  box-shadow: 0 0 0 2px rgba(21,101,192,0.15);
}

.form-group input[readonly] { background: #f5f7fa; color: #666; }
.form-group-check { justify-content: flex-end; padding-bottom: 2px; }
.form-group-check label { flex-direction: row; gap: 6px; align-items: center; font-size: 13px; }

/* ── DB Instance List (Settings) ─────────────────────────────────────────── */

.db-instance-row {
  display: grid;
  grid-template-columns: 110px 140px 140px 70px 100px 1fr 32px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.db-instance-row input,
.db-instance-row select {
  padding: 5px 8px;
  border: 1px solid #c8d0dc;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  width: 100%;
}

.db-instance-row input:focus,
.db-instance-row select:focus { outline: none; border-color: #1565c0; }

.db-instance-labels {
  display: grid;
  grid-template-columns: 110px 140px 140px 70px 100px 1fr 32px;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.btn-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 16px;
  border: 1px solid #e5e9f0;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  color: #c62828;
}

.btn-icon:hover { background: #fee2e2; border-color: #c62828; }

/* ── Filter Bar ──────────────────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  gap: 8px;
  padding: 7px 16px;
  background: #f8f9fb;
  border-bottom: 1px solid #dde3ec;
  flex-shrink: 0;
}

.filter-bar input,
.filter-bar select {
  padding: 5px 10px;
  border: 1px solid #c8d0dc;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  color: #1a1a2e;
  background: #fff;
}

.filter-bar input { flex: 1; min-width: 200px; }

.filter-bar input:focus,
.filter-bar select:focus {
  outline: none;
  border-color: #1565c0;
  box-shadow: 0 0 0 2px rgba(21,101,192,0.15);
}

/* ── Current Access cell ─────────────────────────────────────────────────── */

.access-cell {
  white-space: normal;
  vertical-align: top;
  max-width: 300px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11px;
}

.access-cell .grant-line {
  padding: 1px 0;
  line-height: 1.45;
}

/* ── DB Users Modal ──────────────────────────────────────────────────────── */

.db-users-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.db-users-toolbar select {
  padding: 5px 10px;
  border: 1px solid #c8d0dc;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}

.db-users-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.db-users-table thead { background: #e8edf4; }

.db-users-table th {
  padding: 8px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #4a5568;
  border-bottom: 2px solid #c9d2e0;
  white-space: nowrap;
}

.db-users-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #edf0f5;
  vertical-align: top;
  white-space: normal;
  max-width: none;
}

.grants-cell {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11px;
}

.grants-cell .grant-line { padding: 1px 0; line-height: 1.5; }

.no-grants { color: #aaa; font-style: italic; }

.db-users-empty, .db-users-error { padding: 24px 0; text-align: center; color: #999; }
.db-users-error { color: #c62828; }

/* ── Audit Log Modal ─────────────────────────────────────────────────────── */

.audit-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.audit-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 12px;
}

.audit-table thead { background: #e8edf4; }

.audit-table th {
  padding: 7px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: #4a5568;
  border-bottom: 2px solid #c9d2e0;
  white-space: nowrap;
}

.audit-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #edf0f5;
  vertical-align: top;
  white-space: normal;
  max-width: none;
  font-family: 'Consolas', 'Courier New', monospace;
}

.audit-table td:first-child { white-space: nowrap; color: #666; }

.badge-audit-create  { background: #dcfce7; color: #166534; }
.badge-audit-update  { background: #dbeafe; color: #1d4ed8; }
.badge-audit-delete  { background: #fee2e2; color: #991b1b; }
.badge-audit-process { background: #fef3c7; color: #92400e; }
.badge-audit-revoke  { background: #f3e8ff; color: #6b21a8; }
.badge-audit-default { background: #e5e7eb; color: #374151; }

.audit-empty, .audit-error { padding: 24px 0; text-align: center; color: #999; }
.audit-error { color: #c62828; }

/* ── Bulk Revoke Modal ───────────────────────────────────────────────────── */

.bulk-revoke-warning {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 13px;
  color: #856404;
  line-height: 1.5;
}

.revoke-log {
  margin-top: 16px;
  background: #1a1a2e;
  color: #e2e8f0;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  padding: 10px 14px;
  border-radius: 4px;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.6;
}
