/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #1a3a5c;
  --primary-light: #2a5a8c;
  --primary-dark: #0d2035;
  --accent: #e67e22;
  --accent-light: #f39c12;
  --success: #27ae60;
  --danger: #e74c3c;
  --warning: #f39c12;
  --bg: #f0f4f8;
  --bg-card: #ffffff;
  --bg-sidebar: #1a3a5c;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --text-muted: #95a5a6;
  --border: #dce6f0;
  --border-light: #eaf0f6;
  --shadow: 0 2px 12px rgba(26,58,92,0.10);
  --shadow-lg: 0 8px 32px rgba(26,58,92,0.15);
  --radius: 10px;
  --radius-sm: 6px;
  --topbar-h: 58px;
  --sidebar-w: 220px;
  --sidebar-w-collapsed: 0px;
  --transition: 0.22s ease;
}

html { font-size: 15px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }
a { color: var(--primary); text-decoration: none; cursor: pointer; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 0.95rem; }

/* ===== LOGIN ===== */
.login-overlay { position: fixed; inset: 0; background: linear-gradient(135deg, #1a3a5c 0%, #2d6a9f 100%); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.login-card { background: white; border-radius: 16px; padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.login-logo h1 { font-size: 1.4rem; color: var(--primary); font-weight: 700; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius-sm); font-size: 0.88rem; font-weight: 500; border: none; transition: all var(--transition); white-space: nowrap; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary { background: white; color: var(--primary); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--bg); border-color: var(--primary); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-full { width: 100%; justify-content: center; padding: 11px; font-size: 1rem; }
.btn-icon { background: none; border: none; padding: 6px; border-radius: 6px; color: rgba(255,255,255,0.85); display: flex; align-items: center; }
.btn-icon:hover { background: rgba(255,255,255,0.15); color: white; }

/* ===== FORM ELEMENTS ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-light); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.04em; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: white; color: var(--text); transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(42,90,140,0.12);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ===== ALERTS ===== */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 0.88rem; margin-bottom: 12px; }
.alert-danger { background: #fde8e8; color: #c0392b; border: 1px solid #f5c6c6; }
.alert-success { background: #e8f8ef; color: #1e8449; border: 1px solid #a9dfbf; }
.alert-warning { background: #fef9e7; color: #b7770d; border: 1px solid #fad7a0; }

/* ===== TOPBAR ===== */
.topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); background: var(--primary); color: white; display: flex; align-items: center; justify-content: space-between; padding: 0 16px 0 12px; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.app-title { font-size: 1.1rem; font-weight: 700; color: white; letter-spacing: -0.01em; }
.app-icon { border-radius: 8px; }
.menu-toggle { background: none; border: none; padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 5px; }
.menu-toggle span { display: block; width: 22px; height: 2.5px; background: white; border-radius: 2px; transition: all var(--transition); }
.user-badge { background: rgba(255,255,255,0.2); color: white; padding: 4px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }

/* ===== SIDEBAR ===== */
.sidebar { position: fixed; top: var(--topbar-h); left: 0; width: var(--sidebar-w); height: calc(100vh - var(--topbar-h)); background: var(--primary); display: flex; flex-direction: column; z-index: 90; transition: transform var(--transition); overflow: hidden; }
.sidebar.collapsed { transform: translateX(-100%); }
.sidebar-nav { flex: 1; padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius-sm); color: rgba(255,255,255,0.75); font-size: 0.9rem; font-weight: 500; transition: all var(--transition); cursor: pointer; }
.nav-item:hover { background: rgba(255,255,255,0.12); color: white; }
.nav-item.active { background: rgba(255,255,255,0.18); color: white; }
.nav-divider { height: 1px; background: rgba(255,255,255,0.12); margin: 10px 0; }
.sidebar-footer { padding: 14px 16px; color: rgba(255,255,255,0.4); font-size: 0.75rem; }

/* ===== MAIN CONTENT ===== */
.content { margin-top: var(--topbar-h); margin-left: var(--sidebar-w); padding: 24px; min-height: calc(100vh - var(--topbar-h)); transition: margin-left var(--transition); }
.content.sidebar-collapsed { margin-left: 0; }

/* ===== PAGE HEADER ===== */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-input { padding: 7px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 0.88rem; width: 180px; }
.search-input:focus { outline: none; border-color: var(--primary-light); }
.filter-select { padding: 7px 10px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 0.88rem; }

/* ===== TABS ===== */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== OBJECTS LAYOUT ===== */
.objects-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.objects-layout.with-company { grid-template-columns: 280px 1fr 340px; }

.panel { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-list { max-height: calc(100vh - 160px); overflow-y: auto; }
.panel-detail { padding: 0; max-height: calc(100vh - 160px); overflow-y: auto; }
.panel-company-detail { padding: 0; max-height: calc(100vh - 160px); overflow-y: auto; }

/* ===== ITEM LIST ===== */
.item-list { list-style: none; }
.item-list-item { padding: 13px 16px; border-bottom: 1px solid var(--border-light); cursor: pointer; transition: background var(--transition); display: flex; flex-direction: column; gap: 3px; }
.item-list-item:hover { background: var(--bg); }
.item-list-item.selected { background: #e8f0fb; border-left: 3px solid var(--primary); }
.item-list-item:last-child { border-bottom: none; }
.item-title { font-weight: 600; font-size: 0.92rem; color: var(--text); }
.item-subtitle { font-size: 0.80rem; color: var(--text-light); }
.item-meta { display: flex; gap: 6px; margin-top: 2px; }
.badge { font-size: 0.70rem; padding: 2px 7px; border-radius: 20px; font-weight: 600; }
.badge-weg { background: #dbeafe; color: #1d4ed8; }
.badge-miet { background: #dcfce7; color: #15803d; }
.badge-count { background: var(--bg); color: var(--text-light); }

/* ===== DETAIL PANELS ===== */
.detail-header { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: white; padding: 20px; border-radius: var(--radius) var(--radius) 0 0; }
.detail-header h3 { font-size: 1.15rem; font-weight: 700; }
.detail-header .detail-subtitle { opacity: 0.8; font-size: 0.85rem; margin-top: 4px; }
.detail-actions { display: flex; gap: 8px; margin-top: 14px; }
.detail-actions .btn { font-size: 0.80rem; padding: 5px 12px; }
.btn-outline-white { background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.3); }
.btn-outline-white:hover { background: rgba(255,255,255,0.25); }

.detail-body { padding: 20px; }
.detail-body .object-image { width: 100%; max-height: 180px; object-fit: cover; border-radius: var(--radius-sm); margin-bottom: 16px; }

.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.info-item { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.info-value { font-size: 0.88rem; color: var(--text); font-weight: 500; }

/* ===== SECTION HEADER ===== */
.section-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px 10px; border-bottom: 1px solid var(--border-light); }
.section-header h3 { font-size: 1rem; font-weight: 700; color: var(--primary); }

/* ===== ASSIGNED COMPANIES ===== */
.assigned-list { list-style: none; }
.assigned-item { padding: 12px 20px; border-bottom: 1px solid var(--border-light); cursor: pointer; transition: background var(--transition); }
.assigned-item:hover { background: var(--bg); }
.assigned-item.selected { background: #fef3e8; border-left: 3px solid var(--accent); }
.assigned-item-header { display: flex; align-items: center; justify-content: space-between; }
.assigned-item-name { font-weight: 600; font-size: 0.9rem; }
.assigned-item-trade { font-size: 0.78rem; color: var(--accent); font-weight: 600; }
.assigned-item-contact { font-size: 0.78rem; color: var(--text-light); margin-top: 3px; }

/* ===== COMPANIES GRID ===== */
.companies-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.company-card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border-light); overflow: hidden; transition: box-shadow var(--transition), transform var(--transition); }
.company-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.company-card-header { background: linear-gradient(135deg, var(--primary), var(--primary-light)); padding: 14px 16px; color: white; }
.company-card-header h3 { font-size: 0.95rem; font-weight: 700; }
.company-card-header .trades { font-size: 0.75rem; opacity: 0.85; margin-top: 4px; }
.company-card-body { padding: 14px 16px; }
.company-contact-row { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--text-light); margin-bottom: 5px; }
.company-contact-row svg { flex-shrink: 0; opacity: 0.6; }
.company-card-actions { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border-light); }

/* ===== DETAILS TABLE ===== */
.details-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 12px; }
.details-table th { text-align: left; padding: 8px 10px; background: var(--bg); color: var(--text-light); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 2px solid var(--border); }
.details-table td { padding: 9px 10px; border-bottom: 1px solid var(--border-light); }
.details-table tr:last-child td { border-bottom: none; }
.details-table tr:hover td { background: var(--bg); }

/* ===== USERS TABLE ===== */
.data-table { width: 100%; background: white; border-radius: var(--radius); box-shadow: var(--shadow); border-collapse: collapse; overflow: hidden; }
.data-table thead { background: var(--primary); color: white; }
.data-table th { padding: 12px 16px; text-align: left; font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table td { padding: 11px 16px; border-bottom: 1px solid var(--border-light); font-size: 0.88rem; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg); }

/* ===== MODAL ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 500; display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(3px); }
.modal { background: white; border-radius: 14px; width: 100%; max-width: 620px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-lg { max-width: 780px; }
.modal-header { padding: 18px 22px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 1.05rem; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== TOAST ===== */
.toast { position: fixed; bottom: 24px; right: 24px; z-index: 9999; padding: 12px 20px; border-radius: var(--radius-sm); font-size: 0.88rem; font-weight: 500; box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease; }
.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-warning { background: var(--warning); color: white; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== HINT ===== */
.hint-text { color: var(--text-muted); font-size: 0.9rem; padding: 20px; text-align: center; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state svg { opacity: 0.3; margin-bottom: 12px; }

/* ===== CONTRACT INFO ===== */
.contract-box { background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin-top: 12px; }
.contract-box h4 { font-size: 0.85rem; font-weight: 700; color: var(--primary); margin-bottom: 10px; }
.contract-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.contract-item .label { font-size: 0.70rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.contract-item .value { font-size: 0.84rem; font-weight: 500; color: var(--text); }

/* ===== LOADING ===== */
.loading { display: flex; align-items: center; justify-content: center; padding: 32px; color: var(--text-muted); font-size: 0.88rem; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin-right: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; }
  .objects-layout { grid-template-columns: 1fr; }
  .objects-layout.with-company { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .content { padding: 16px 12px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .companies-grid { grid-template-columns: 1fr; }
  .modal { max-height: 95vh; }
  .contract-grid { grid-template-columns: 1fr; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== PRINT ===== */
@media print {
  .sidebar, .topbar, .page-actions, .btn { display: none !important; }
  .content { margin: 0; padding: 0; }
}

/* ===== OBJEKTNUMMER-BADGE ===== */
.obj-number {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: white;
  font-size: 0.70rem; font-weight: 700;
  padding: 2px 7px; border-radius: 4px;
  min-width: 28px; flex-shrink: 0;
  letter-spacing: 0.03em;
}

/* ===== AUFTRAGSNUMMER-BADGE ===== */
.order-number-badge {
  display: inline-block;
  background: #f0f4f8; color: var(--primary);
  font-family: 'Courier New', monospace;
  font-size: 0.78rem; font-weight: 700;
  padding: 3px 8px; border-radius: 4px;
  border: 1px solid var(--border);
  letter-spacing: 0.04em; white-space: nowrap;
}

/* ===== APP TITLE BLOCK ===== */
.app-title-block { display: flex; flex-direction: column; }
.app-title { font-size: 0.95rem; font-weight: 700; color: white; letter-spacing: -0.01em; line-height: 1.2; }
@media (max-width: 600px) {
  .app-title { font-size: 0.78rem; }
}

/* ===== SETTINGS PANEL ===== */
#settingsContainer .panel { background: white; }
