/* Agency OS — Responsive Layout */

/* ── Grundlayout: kein horizontaler Seiten-Scroll ── */
.flex.min-h-screen > .flex-1 {
  min-width: 0;
  max-width: 100%;
}

main {
  overflow-x: hidden;
  width: 100%;
}

.input,
select.input,
textarea.input {
  max-width: 100%;
}

/* ── Überschriften auf kleinen Screens ── */
@media (max-width: 639px) {
  main h1.text-3xl {
    font-size: 1.5rem;
    line-height: 1.25;
  }

  main h1.text-4xl {
    font-size: 1.75rem;
  }
}

/* ── Detailseiten (Kunde, Projekt): Kopf + Buttons ── */
.detail-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.detail-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
}

@media (min-width: 640px) {
  .detail-header {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
  }

  .detail-header-actions {
    width: auto;
    justify-content: flex-end;
  }
}

/* ── Tabellen: horizontal scrollen ── */
.table-scroll,
.card.table-card {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  position: relative;
  border-radius: var(--radius-lg);
}

.table-scroll table,
.card.table-card table {
  min-width: 36rem;
  background: var(--bg-card);
}

@media (max-width: 767px) {
  .table-scroll table,
  .card.table-card table {
    min-width: 22rem;
  }

  .table-scroll table th,
  .table-scroll table td,
  .card.table-card table th,
  .card.table-card table td {
    padding: 0.75rem 0.625rem;
    font-size: 0.8125rem;
  }

  .table-scroll table thead th:first-child,
  .table-scroll table tbody td:first-child,
  .card.table-card table thead th:first-child,
  .card.table-card table tbody td:first-child {
    padding-left: 1rem;
  }

  .table-scroll table td:last-child:not(.table-actions-cell),
  .card.table-card table td:last-child:not(.table-actions-cell) {
    white-space: normal;
    max-width: 9rem;
  }
}

.table-scroll table th,
.table-scroll table td,
.card.table-card table th,
.card.table-card table td {
  white-space: nowrap;
}

.table-scroll table th:first-child,
.table-scroll table td:first-child,
.card.table-card table th:first-child,
.card.table-card table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
}

.table-scroll table thead th,
.card.table-card table thead th {
  background: var(--bg-card);
  padding: 1rem;
}

.table-scroll table thead th:first-child,
.table-scroll table tbody td:first-child,
.card.table-card table thead th:first-child,
.card.table-card table tbody td:first-child {
  padding-left: 1.25rem;
}

.table-scroll table thead th:first-child,
.card.table-card table thead th:first-child {
  z-index: 2;
  border-top-left-radius: var(--radius-lg);
  box-shadow: none;
}

.table-scroll table tbody td:first-child,
.card.table-card table tbody td:first-child {
  background: var(--bg-card);
}

.table-scroll table tbody tr:last-child td:first-child,
.card.table-card table tbody tr:last-child td:first-child {
  border-bottom-left-radius: var(--radius-lg);
}

.table-scroll tbody tr td,
.card.table-card tbody tr td {
  transition: background-color 0.15s ease;
}

.table-scroll tbody tr:hover td,
.card.table-card tbody tr:hover td {
  background: var(--bg-hover);
}

/* Weniger wichtige Spalten auf dem Handy ausblenden */
@media (max-width: 767px) {
  .hide-mobile,
  th.hide-mobile,
  td.hide-mobile {
    display: none !important;
  }
}

/* Hinweis: Tabelle wischen (nur wenn breiter als Container) */
@media (max-width: 767px) {
  .table-scroll::after,
  .card.table-card.table-scroll::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 2rem;
    pointer-events: none;
    background: linear-gradient(to left, var(--bg-card), transparent);
  }
}

/* ── Seitenkopf & Aktionsleisten ── */
.page-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 2rem;
}

@media (min-width: 640px) {
  .page-header {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
  }
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
}

@media (min-width: 640px) {
  .page-actions {
    width: auto;
    justify-content: flex-end;
  }
}

/* ── Formulare ── */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 639px) {
  .filter-form .w-48,
  .filter-form .w-44,
  .filter-form .w-40,
  .filter-form .w-36 {
    width: 100%;
  }

  .filter-form .flex-1 {
    min-width: 100%;
  }
}

/* ── Kanban ── */
.kanban-board {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}

.kanban-board > .kanban-col {
  flex: 0 0 min(100%, 280px);
  scroll-snap-align: start;
}

/* ── Tabs (Kunden, Projekt, Einstellungen) ── */
.tabs-bar {
  position: relative;
  margin-bottom: 1.5rem;
}

.tabs-bar--sticky {
  position: sticky;
  top: 3.5rem;
  z-index: 20;
  padding: 0.5rem 0 0.75rem;
  margin-bottom: 1.25rem;
  background: linear-gradient(
    to bottom,
    var(--bg) 0%,
    var(--bg) 72%,
    transparent 100%
  );
}

.tabs-bar--nested {
  margin-bottom: 1.25rem;
}

.tabs-bar--nested .tabs-scroll .tab-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  border-radius: 0.5rem;
}

.tab-btn--link {
  text-decoration: none;
}

.tab-btn--link .tab-btn__label::after {
  content: '↗';
  margin-left: 0.25rem;
  font-size: 0.65em;
  opacity: 0.55;
}

.tabs-bar::before,
.tabs-bar::after {
  content: '';
  position: absolute;
  top: 0.5rem;
  bottom: 0.75rem;
  width: 1.75rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.tabs-bar::before {
  left: 0;
  background: linear-gradient(to right, var(--bg), transparent);
}

.tabs-bar::after {
  right: 0;
  background: linear-gradient(to left, var(--bg), transparent);
}

.tabs-bar--scroll-left::before,
.tabs-bar--scroll-right::after {
  opacity: 1;
}

.tabs-scroll {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  background: color-mix(in srgb, var(--bg-elevated) 88%, var(--bg) 12%);
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.tabs-scroll::-webkit-scrollbar {
  display: none;
}

.tabs-group {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  flex-shrink: 0;
}

.tabs-group--end {
  margin-left: auto;
}

.tabs-group-divider {
  width: 1px;
  align-self: stretch;
  margin: 0.35rem 0.125rem;
  background: var(--border);
  flex-shrink: 0;
}

.tabs-scroll button,
.tabs-scroll a {
  flex-shrink: 0;
}

.tabs-scroll .tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  font-size: 0.8125rem;
  line-height: 1.2;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: 0.625rem;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.tabs-scroll .tab-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--bg-hover) 70%, transparent);
}

.tabs-scroll .tab-btn.is-active,
.tabs-scroll .tab-btn[aria-selected="true"] {
  color: var(--text);
  font-weight: 600;
  background: var(--bg);
  border-color: var(--border-strong);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.tab-btn__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.tab-btn__badge--count {
  background: color-mix(in srgb, var(--text-faint) 14%, var(--bg-elevated));
  color: var(--text-muted);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.tab-btn.is-active .tab-btn__badge--count,
.tab-btn[aria-selected="true"] .tab-btn__badge--count {
  background: color-mix(in srgb, var(--accent) 14%, var(--bg));
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 28%, var(--border));
}

.tab-btn__badge--alert {
  background: var(--rose);
  color: #fff;
  border: 1px solid color-mix(in srgb, var(--rose) 75%, #000);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.tab-btn__indicator {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.tab-btn__indicator--ok {
  background: #34d399;
  box-shadow: 0 0 0 2px color-mix(in srgb, #34d399 25%, transparent);
}

/* Hellmodus: Tabs und Badges mit höherem Kontrast */
[data-theme="light"] .tabs-scroll {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

[data-theme="light"] .tabs-scroll .tab-btn {
  color: var(--text-muted);
  font-weight: 600;
}

[data-theme="light"] .tabs-scroll .tab-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

[data-theme="light"] .tabs-scroll .tab-btn.is-active,
[data-theme="light"] .tabs-scroll .tab-btn[aria-selected="true"] {
  color: var(--text);
  background: #f5f0e8;
  border-color: var(--border-strong);
  box-shadow: inset 0 0 0 1px rgba(28, 20, 12, 0.06), var(--shadow-sm);
}

[data-theme="light"] .tab-btn__badge--count {
  background: #e7e5e4;
  color: #292524;
  border-color: #a8a29e;
}

[data-theme="light"] .tab-btn.is-active .tab-btn__badge--count,
[data-theme="light"] .tab-btn[aria-selected="true"] .tab-btn__badge--count {
  background: #fff;
  color: #1c1917;
  border-color: #78716c;
}

[data-theme="light"] .tab-btn__badge--alert {
  background: #dc2626;
  color: #fff;
  border-color: #991b1b;
}

.tab-panel {
  animation: tab-panel-in 0.2s ease;
}

@keyframes tab-panel-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 639px) {
  .tabs-bar--sticky {
    top: 3.5rem;
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }

  .tabs-scroll .tab-btn {
    padding: 0.45rem 0.7rem;
    font-size: 0.75rem;
  }
}

/* ── Mobile Editor-Leiste ── */
.editor-mobile-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  height: 3rem;
  position: sticky;
  top: 0;
  z-index: 35;
}

/* ── Dashboard ── */
@media (max-width: 767px) {
  /* Auf kleinen Phones: alle Widgets volle Breite */
  #dashboard-widgets .widget {
    grid-column: span 1 / span 1 !important;
  }

  /* Clients-Kacheln: 2 Spalten auch auf kleinen Screens */
  #dashboard-widgets [data-widget="clients"] .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Deadlines: einspaltig auf Mobile */
  #dashboard-widgets [data-widget="deadlines"] ul {
    grid-template-columns: 1fr !important;
  }

  #dashboard-widgets [data-widget="deadlines"] li {
    grid-template-columns: 5.5rem minmax(0, 1fr);
  }
}

@media (max-width: 479px) {
  #dashboard-widgets [data-widget="deadlines"] li {
    grid-template-columns: 1fr;
    gap: 0.125rem;
  }

  #dashboard-widgets [data-widget="deadlines"] li > span:first-child {
    margin-bottom: 0.125rem;
  }
}

/* ── Topbar: kompakter auf kleinen Screens ── */
@media (max-width: 639px) {
  header.sticky.top-0 {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    gap: 0.5rem;
  }

  #open-search span:not(.flex-1) {
    display: none;
  }

  #open-search .flex-1 {
    font-size: 0.8125rem;
  }

  /* Benachrichtigungs-Dropdown: am Viewport ausrichten, nicht am Glocken-Button */
  .notification-panel {
    position: fixed;
    top: calc(3.5rem + 0.5rem + env(safe-area-inset-top, 0px));
    right: max(0.75rem, env(safe-area-inset-right, 0px));
    left: max(0.75rem, env(safe-area-inset-left, 0px));
    width: auto;
    max-width: none;
    z-index: 60;
  }

  .notification-item__title,
  .notification-item__meta {
    overflow-wrap: anywhere;
  }
}

/* ── Mobile Sidebar: scrollbares Menü ── */
.mobile-sidebar-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  padding: 1.25rem;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
}

.mobile-sidebar-header {
  flex-shrink: 0;
  margin-bottom: 1.5rem;
}

.mobile-sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-right: 0.125rem;
}

.mobile-sidebar-footer {
  flex-shrink: 0;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.mobile-sidebar-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
}

/* ── Modals ── */
@media (max-width: 639px) {
  #quick-task-modal .glass-panel,
  #quick-time-modal .glass-panel,
  .command-palette-inner {
    margin-left: 0.75rem;
    margin-right: 0.75rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }
}

/* Safe area (Notch) */
@supports (padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .editor-mobile-bar,
  header.sticky.top-0 {
    padding-top: env(safe-area-inset-top);
  }
}
