/**
 * PMDM App - Main Stylesheet
 * Extracted from _app.tsx for better maintainability
 */

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #f4f6fb;
  min-height: 100vh;
  color: #1f2933;
}

a {
  color: inherit;
}

/* Auth */
.auth-container {
  background: white;
  padding: 3rem;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  max-width: 500px;
  width: 90%;
  text-align: center;
  margin: 4rem auto;
}

/* Buttons */
.button {
  background: #1d4ed8;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.2s;
  font-weight: 600;
}

.button:hover {
  background: #1e40af;
}

.button-secondary {
  background: #64748b;
}

.button-secondary:hover {
  background: #475569;
}

/* App Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-nav {
  width: 260px;
  background: linear-gradient(180deg, #1d4ed8 0%, #1e3a8a 100%);
  color: white;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.nav-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-links a {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.9);
  transition: background 0.2s;
}

.nav-links a.active,
.nav-links a:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.nav-footer {
  margin-top: auto;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.nav-logout {
  margin-top: 0.5rem;
}

.app-layout-superuser {
  border: 5px solid #dc2626;
  border-radius: 12px;
}

.app-main {
  flex: 1;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.layout-main {
  flex: 1;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* App Info Header */
.app-info {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 15px 30px rgba(15, 23, 42, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.section-title {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Panels */
.app-panels {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.app-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panels-two-column {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
  align-items: start;
}

.panel {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-secondary {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  box-shadow: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.panel-title {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Status Pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-active {
  background: rgba(34, 197, 94, 0.15);
  color: #15803d;
}

.status-inactive {
  background: rgba(248, 113, 113, 0.15);
  color: #b91c1c;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.4rem;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.95rem;
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.table-scroll {
  max-height: 420px;
  overflow: auto;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
}

input[type="text"], textarea, select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid #cbd5f5;
  border-radius: 8px;
  margin-top: 0.3rem;
  font-size: 0.95rem;
}

/* Utility: unified text-like input styling (overrides browser UA defaults) */
.textlike-input {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border: 1px solid #cbd5f5;
  border-radius: 8px;
  margin-top: 0;
  font-size: 0.9rem;
  font-family: inherit;
  box-sizing: border-box;
  background: white;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.actions-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Badges */
.badge {
  background: rgba(14, 165, 233, 0.15);
  color: #0369a1;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Segmented Control */
.segmented-control {
  display: inline-flex;
  border: 1px solid #cbd5f5;
  border-radius: 999px;
  overflow: hidden;
}

.segmented-control a {
  padding: 0.35rem 0.75rem;
  text-decoration: none;
  font-size: 0.85rem;
  color: #334155;
}

.segmented-control a.active {
  background: #1d4ed8;
  color: white;
}

/* Create Section Layout (admin list panels) */
.create-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

/* Create fields: labels always above inputs */
.create-fields label {
  display: block;
  margin-top: 0;
  margin-bottom: 0.35rem;
}

/* Create fields: 2-column layout (Name 1x, Description 2x) */
.create-two-col {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  width: 100%;
  flex-wrap: wrap;
}

.create-col-name {
  flex: 1 1 0;
  min-width: 220px;
}

.create-col-description {
  flex: 2 1 0;
  min-width: 320px;
}

/* Create fields: use the same compact look as inline-edit inputs */
.create-two-col input[type="text"],
.create-two-col textarea {
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-top: 0;
  border: 1px solid #cbd5f5;
  background: white;
  font-family: inherit;
  box-sizing: border-box;
}

/* Table control header closer to table */
.panel-header.table-controls {
  padding-bottom: 0.25rem;
}

/* Inline Edit Cells */
.inline-edit {
  margin: 0;
}

.inline-edit-row {
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
}

/* Inline edit inputs should fill the available table cell width */
.inline-edit-row .inline-edit-input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  max-width: none;
}

/* Compact inline edit look inside tables */
table .inline-edit-input {
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

/* Make create inputs in simple admin panels match the inline-edit look */
.create-row .create-fields input[type="text"],
.create-row .create-fields textarea {
  font-family: inherit;
  border: 1px solid #cbd5f5;
  background: white;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-top: 0;
}

.create-row .create-fields {
  flex: 1 1 auto;
  min-width: 220px;
}

/* Server-side inline edit: save button only appears when value differs */
.inline-edit .save-button {
  display: none;
}

.inline-edit.dirty .save-button {
  display: inline-flex !important;
}

.inline-edit-input {
  margin-top: 0;
}

.inline-edit-input.inline-edit-textarea {
  min-height: 48px;
}

.entity-name-text {
  font-weight: 600;
  display: block;
  line-height: 1.2;
}

/* Icon Buttons */
.icon-button {
  background: transparent;
  border: 1px solid transparent;
  color: #334155;
  padding: 0.5rem;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  background: rgba(15, 23, 42, 0.06);
  border-color: rgba(15, 23, 42, 0.08);
}

/* Utility Classes */
.cell-muted {
  color: #64748b;
}

/* Responsive */
@media (max-width: 960px) {
  .app-layout {
    flex-direction: column;
  }
  .app-nav {
    width: 100%;
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;
  }
}

/* DoubleList Layout: equal list widths, filters above selects, centered buttons */
.double-list-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.75rem;
  align-items: stretch;
}

.double-list-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.double-list-filter {
  width: 100%;
}

.double-list-select {
  width: 100%;
}

.double-list-actions-center {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}
