/* =========================================================================
   TOKENS
   ========================================================================= */
:root {
  --bg: #0362a1;
  --surface: #035497;
  --surface-alt: #024272;
  --border: rgba(255, 255, 255, 0.16);
  --text-primary: #ffffff;
  --text-secondary: #ffffff;
  --text-muted: #9fc3dd;

  --accent: #2e8fe0;
  --accent-hover: #1c74bd;
  --accent-soft: #e5f2fb;
  --accent-contrast: #ffffff;

  --danger: #e63946;
  --danger-hover: #99000d;
  --danger-soft: #5e0803;

  --ink: #06304f;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --shadow-sm: 0 1px 2px rgba(2, 15, 27, 0.18);
  --shadow-md: 0 6px 20px rgba(2, 15, 27, 0.28);
  --shadow-lg: 0 20px 48px rgba(2, 15, 27, 0.4);

  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }

/* Garante que o atributo `hidden` sempre vença regras de display definidas
   em classes (ex.: .login-screen / .modal-overlay usam display:flex),
   evitando telas e modais que "não fecham" mesmo com hidden=true. */
[hidden] {
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2 {
  font-family: var(--font-display);
  margin: 0;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 15px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* =========================================================================
   BOTÕES
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--text-primary); }

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-outline-danger:hover { background: var(--danger-soft); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-block { width: 100%; }

.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
.btn-ghost .spinner, .btn-outline-danger .spinner {
  border-color: rgba(46, 143, 224, 0.3);
  border-top-color: var(--accent);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   LOGIN
   ========================================================================= */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.08), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(255, 255, 255, 0.06), transparent 45%),
    var(--bg);
}

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

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.brand-mark {
  height: 44px;
  width: auto;
  display: block;
  margin: 0 auto 14px;
}

.login-brand h1 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.login-brand p {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 12px;
}

.login-form input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-primary);
}
.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-form .btn {
  margin-top: 22px;
}

.login-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  text-align: center;
}

/* =========================================================================
   CABEÇALHO DA APLICAÇÃO
   ========================================================================= */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark-sm { height: 28px; width: auto; margin: 0; flex-shrink: 0; }

.header-title h1 {
  font-size: 17px;
  font-weight: 700;
}

.header-title p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.header-actions .icon { font-size: 16px; }

/* =========================================================================
   CONTEÚDO PRINCIPAL
   ========================================================================= */
.app-main {
  padding: 24px 28px 48px;
  max-width: 1600px;
  margin: 0 auto;
}

/* Cadastro rápido */
.quick-add-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
  margin-bottom: 20px;
}

.quick-add-card h2 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text-primary);
}

.service-form {
  display: grid;
  grid-template-columns: 1fr 1fr 0.8fr 2.2fr auto;
  gap: 14px;
  align-items: end;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.field select,
.field input,
.field textarea {
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-primary);
  width: 100%;
}

.field select:focus,
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field textarea {
  resize: vertical;
  min-height: 42px;
  font-family: var(--font-body);
}

.field-submit { height: 42px; }

/* Filtro */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.filter-bar label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.filter-bar select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
}

.sync-indicator {
  font-size: 12.5px;
  color: var(--accent);
  margin-left: auto;
}

/* =========================================================================
   QUADRO SEMANAL (KANBAN)
   ========================================================================= */
.board-wrapper {
  overflow-x: auto;
  padding-bottom: 8px;
}

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(280px, 1fr);
  gap: 14px;
  min-width: 100%;
}

.day-column {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.day-column-header {
  padding: 12px 14px 10px;
  border-bottom: 1px dashed var(--border);
  position: relative;
}

.day-column-header::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: -1px;
  height: 3px;
  background: repeating-linear-gradient(
    to right,
    var(--accent) 0,
    var(--accent) 5px,
    transparent 5px,
    transparent 11px
  );
  opacity: 0.35;
}

.day-column-header h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.day-column-header span {
  font-size: 11.5px;
  color: var(--text-muted);
}

.day-column-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.day-empty {
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
  padding: 18px 8px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* Cartão de serviço */
.service-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}
.service-card:hover { box-shadow: var(--shadow-md); }

.service-card-main {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 10px 10px 12px;
  cursor: pointer;
}

.service-time {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 7px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 1px;
}

.service-tech {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.35;
  padding-top: 2px;
}

.expand-arrow {
  font-size: 11px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  margin-top: 4px;
}
.service-card.expanded .expand-arrow { transform: rotate(180deg); }

.options-btn {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
  position: relative;
  margin-top: -1px;
}
.options-btn:hover { background: var(--surface-alt); color: var(--text-primary); }

.options-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 10;
  min-width: 110px;
  overflow: hidden;
}

.options-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  background: none;
  border: none;
  font-size: 13.5px;
  color: var(--text-primary);
  cursor: pointer;
}
.options-menu button:hover { background: var(--surface-alt); }
.options-menu button.danger { color: var(--danger); }

.service-details {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  border-top: 1px solid transparent;
}

.service-card.expanded .service-details {
  /* Alto o suficiente para não cortar textos longos; como o texto real
     nunca chega perto disso, a transição continua parecendo suave. */
  max-height: 4000px;
  padding: 10px 12px 12px 12px;
  border-top: 1px solid var(--border);
}

/* =========================================================================
   MODAIS
   ========================================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 34, 48, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 26px 26px 22px;
  width: 100%;
  max-width: 420px;
}

.modal-sm { max-width: 380px; }

.modal h2 {
  font-size: 17px;
  margin-bottom: 14px;
}

.modal p { color: var(--text-secondary); font-size: 14.5px; line-height: 1.5; }

.modal-warning {
  color: var(--danger);
  font-weight: 600;
  background: var(--danger-soft);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
}

.modal .field { margin-bottom: 14px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* =========================================================================
   TOAST
   ========================================================================= */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: toast-in 0.2s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* =========================================================================
   RESPONSIVIDADE
   ========================================================================= */
@media (max-width: 900px) {
  .service-form {
    grid-template-columns: 1fr 1fr;
  }
  .field-detalhes { grid-column: 1 / -1; }
  .field-submit { grid-column: 1 / -1; height: 44px; }
}

@media (max-width: 640px) {
  .app-header {
    padding: 14px 16px;
  }
  .btn-text { display: none; }
  .app-main { padding: 16px 16px 40px; }
  .service-form { grid-template-columns: 1fr; }
  .board {
    grid-auto-columns: minmax(78vw, 1fr);
  }
  .quick-add-card { padding: 16px; }
}
