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

body {
  font-family: system-ui, sans-serif;
  height: 100dvh;
  display: flex;
  background: #f0f2f5;
  color: #111;
}

.hidden { display: none !important; }
.error { color: #d32f2f; font-size: .875rem; min-height: 1.2em; }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.login-box {
  background: #fff;
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.1);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  width: 320px;
}
.login-box h1 { font-size: 1.4rem; text-align: center; color: #128C7E; }
.login-box input, .login-box button {
  padding: .6rem .8rem;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: 1rem;
}
.login-box button {
  background: #128C7E;
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.login-box button:hover { background: #0f7369; }

/* Inbox layout */
#inbox {
  display: flex;
  width: 100%;
  height: 100dvh;
}

/* Sidebar */
#sidebar {
  width: 320px;
  min-width: 280px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
}
#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  background: #128C7E;
  color: #fff;
  font-weight: 600;
}
#sidebar-actions { display: flex; gap: .25rem; }
#logout-btn, #settings-btn { background: none; border: none; color: #fff; font-size: 1.1rem; cursor: pointer; }
#filter-bar { display: flex; border-bottom: 1px solid #e0e0e0; }
.filter-btn {
  flex: 1;
  padding: .5rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .875rem;
  color: #555;
  border-bottom: 2px solid transparent;
}
.filter-btn.active { color: #128C7E; border-bottom-color: #128C7E; font-weight: 600; }
#mine-btn {
  flex: 1;
  padding: .5rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .875rem;
  color: #555;
  border-bottom: 2px solid transparent;
}
#mine-btn.active { background: #e8f5e9; color: #2e7d32; border-bottom-color: #2e7d32; font-weight: 600; }

#conversation-list { list-style: none; overflow-y: auto; flex: 1; }
#conversation-list li {
  padding: .75rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
#conversation-list li:hover { background: #f5f5f5; }
#conversation-list li.active { background: #e8f5e9; }
.conv-name { font-weight: 600; font-size: .95rem; }
.conv-preview { font-size: .8rem; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-agent { font-size: .75rem; color: #128C7E; }

/* Chat */
#chat-panel { flex: 1; display: flex; flex-direction: column; }
#chat-placeholder { margin: auto; color: #999; font-size: 1rem; }

#chat-view { display: flex; flex-direction: column; height: 100%; }
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}
#chat-contact-name { font-weight: 600; display: block; }
#chat-contact-phone { font-size: .8rem; color: #666; }
#chat-actions { display: flex; gap: .5rem; align-items: center; }
#chat-actions select, #close-btn {
  padding: .35rem .6rem;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: .85rem;
  cursor: pointer;
}
#close-btn { background: #e53935; color: #fff; border: none; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  background: #e5ddd5;
}
.message {
  max-width: 65%;
  padding: .5rem .75rem;
  border-radius: 8px;
  font-size: .9rem;
  line-height: 1.4;
  position: relative;
}
.message.inbound { background: #fff; align-self: flex-start; border-bottom-left-radius: 2px; }
.message.outbound { background: #dcf8c6; align-self: flex-end; border-bottom-right-radius: 2px; }
.message time { display: block; font-size: .7rem; color: #999; margin-top: .25rem; text-align: right; }

#chat-footer {
  display: flex;
  gap: .5rem;
  padding: .75rem;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  align-items: flex-end;
}
#reply-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: .5rem .75rem;
  font-size: .95rem;
  resize: none;
  font-family: inherit;
  transition: border-color .15s;
}
#reply-input.note-mode { border-color: #f9a825; background: #fffde7; }
#attach-preview {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .6rem;
  background: #e3f2fd;
  border-radius: 6px;
  font-size: .8rem;
  color: #1565c0;
  margin-bottom: .25rem;
  width: 100%;
}
#attach-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#attach-clear { background: none; border: none; cursor: pointer; color: #1565c0; font-size: .9rem; padding: 0; }
#attach-btn {
  background: #f5f5f5;
  color: #555;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: .3rem .6rem;
  font-size: .9rem;
  cursor: pointer;
}
#attach-btn:hover { background: #e0e0e0; }
#footer-actions { display: flex; flex-direction: column; gap: .4rem; }
#note-btn {
  background: #f5f5f5;
  color: #555;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: .3rem .8rem;
  font-size: .8rem;
  cursor: pointer;
  white-space: nowrap;
}
#note-btn.active { background: #fff9c4; border-color: #f9a825; color: #7a5800; font-weight: 600; }
#send-btn {
  background: #128C7E;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .5rem 1.2rem;
  font-size: .95rem;
  cursor: pointer;
  font-weight: 600;
}
#send-btn:hover { background: #0f7369; }

/* Media in chatvenster */
.media-img { max-width: 100%; max-height: 300px; border-radius: 6px; display: block; }
.media-video { max-width: 100%; max-height: 300px; border-radius: 6px; display: block; }
.media-audio { width: 100%; margin: .25rem 0; }
.media-download {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .4rem .7rem;
  background: #f5f5f5;
  border-radius: 6px;
  color: #1565c0;
  text-decoration: none;
  font-size: .85rem;
  border: 1px solid #ddd;
}
.media-download:hover { background: #e3f2fd; }
.media-caption { font-size: .85rem; margin-top: .35rem; color: #555; }

/* Autoreplies in chatvenster */
.message.autoreply { background: #e8eaf6; align-self: flex-end; border-bottom-right-radius: 2px; border: 1px dashed #9fa8da; }
.autoreply-label { color: #3949ab; }

/* Openingstijden tabel */
.opening-hours-table { width: 100%; border-collapse: collapse; font-size: .875rem; margin: .75rem 0 1.5rem; }
.opening-hours-table th { text-align: left; padding: .35rem .5rem; background: #f5f5f5; color: #555; font-weight: 600; border-bottom: 2px solid #e0e0e0; }
.opening-hours-table td { padding: .4rem .5rem; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.opening-hours-table input[type="time"] { padding: .25rem .4rem; border: 1px solid #ddd; border-radius: 4px; font-size: .85rem; }
.opening-hours-table input[type="time"]:disabled { opacity: .4; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-size: .875rem; font-weight: 600; color: #333; margin-bottom: .75rem; cursor: pointer; }

/* Interne notities in chatvenster */
.message.internal {
  background: #fff9c4;
  border: 1px dashed #f9a825;
  align-self: stretch;
  max-width: 100%;
}
.note-label {
  display: block;
  font-size: .7rem;
  font-weight: 600;
  color: #7a5800;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .25rem;
}

/* Settings */
#settings-panel {
  flex: 1;
  overflow-y: auto;
  background: #f9f9f9;
  display: flex;
  justify-content: center;
}
#settings-content {
  width: 100%;
  max-width: 680px;
  padding: 2rem 1.5rem;
}
#settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
#settings-content h2 {
  font-size: 1.3rem;
  color: #128C7E;
}
#close-settings-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: #666;
  padding: .2rem .4rem;
  border-radius: 4px;
}
#close-settings-btn:hover { background: #e0e0e0; }
#settings-content h3 {
  font-size: 1rem;
  margin: 1.5rem 0 .75rem;
  color: #333;
}
#settings-tabs {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: .5rem;
}
.settings-tab {
  background: none;
  border: none;
  padding: .4rem .9rem;
  cursor: pointer;
  font-size: .9rem;
  color: #555;
  border-radius: 6px 6px 0 0;
}
.settings-tab.active { background: #128C7E; color: #fff; }

.tab-desc {
  font-size: .85rem;
  color: #666;
  margin-bottom: 1rem;
  line-height: 1.5;
}

#tab-profile label, #tab-meta label, #tab-auto label:not(.checkbox-label) {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-bottom: .9rem;
  font-size: .875rem;
  font-weight: 600;
  color: #333;
}
#tab-profile input, #tab-meta input, #tab-auto input[type="number"], #tab-auto textarea {
  padding: .5rem .7rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 400;
  font-family: inherit;
}
#save-profile-btn, #save-meta-btn, #save-auto-btn {
  background: #128C7E;
  color: #fff;
  border: none;
  padding: .5rem 1.4rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  margin-top: .25rem;
}
#save-profile-btn:hover, #save-meta-btn:hover, #save-auto-btn:hover { background: #0f7369; }
.feedback { font-size: .85rem; margin-top: .5rem; min-height: 1.2em; }

/* Gebruikerstabel */
#users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  margin-bottom: 1rem;
}
#users-table th {
  text-align: left;
  padding: .4rem .6rem;
  background: #e8f5e9;
  color: #1b5e20;
  border-bottom: 2px solid #c8e6c9;
}
#users-table td {
  padding: .5rem .6rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
.role-select {
  padding: .25rem .4rem;
  border-radius: 4px;
  border: 1px solid #ddd;
  font-size: .85rem;
}
.delete-user-btn {
  background: #e53935;
  color: #fff;
  border: none;
  padding: .25rem .6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: .8rem;
}
.edit-user-btn {
  background: #f5f5f5;
  border: 1px solid #ddd;
  padding: .25rem .6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: .8rem;
}
.edit-user-btn:hover { background: #e0e0e0; }
.edit-user-row td { background: #f9f9f9; padding: .6rem; }
.edit-user-row input[type="text"],
.edit-user-row input[type="password"] {
  padding: .3rem .5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: .85rem;
  width: 220px;
  margin-right: .4rem;
  margin-bottom: .2rem;
}
.save-user-btn {
  background: #128C7E;
  color: #fff;
  border: none;
  padding: .25rem .6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: .8rem;
}
.save-user-btn:hover { background: #0f7369; }

#add-user-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
}
#add-user-form input, #add-user-form select {
  padding: .45rem .6rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: .875rem;
}
#add-user-btn {
  grid-column: 1 / -1;
  background: #128C7E;
  color: #fff;
  border: none;
  padding: .5rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
}
#add-user-btn:hover { background: #0f7369; }
#add-user-feedback { grid-column: 1 / -1; }
