:root {
  /* Custom properties used throughout the app */
  --header-h: 56px;
  --nav-h: 44px;
  --sidebar-w: 33%;
  --gap: 8px;
}

/* MAIN LAYOUT AND TYPOGRAPHY */

body, p, li, a, button, form, label {
  font-family: arial, georgia, times, serif;
  font-size: 10pt;
}

main {
  margin: 10px;
}

.login-page {
  min-height: calc(100vh - 70px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  box-sizing: border-box;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 24px;
  box-sizing: border-box;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

.login-title {
  margin: 0 0 10px 0;
  font-size: 1rem;
  line-height: 1;
  text-align: center;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 300;
}

.login-field input {
  width: 100%;
  padding: 10px 12px;
  box-sizing: border-box;
  border: 1px solid #bbb;
  border-radius: 8px;
  font: inherit;
}

.login-field input:focus {
  outline: none;
  border-color: #666;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.08);
}

.login-error {
  margin: 4px 0 16px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fdeaea;
  color: #b00020;
  font-weight: 600;
}

.login-button {
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}


.titlebar {
  flex: auto;
  justify-content: space-between;
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 12px;
}

.titlebar .app-title {
  font-size: 18px;
  font-weight: 1000;
  color: rgb(62, 105, 124);
}

#contentTitle {
  font-weight: 800;
  margin: 10px 0;
}

.link {
    color: #0000EE;
    text-decoration: underline;
    cursor: pointer; 
}

.hidden { display: none; }


/* TABLES */

table, th, td {
  border-collapse: collapse;
  border: 1px solid #bbbbbb;
  margin: 10px 0px;
  padding: 3px 1em;
  font-size: 10pt;
  vertical-align: middle;
}
thead {
  background-color: #e6eeee;
}
th {
  padding: 5px 10px 5px 10px;
}
td.date {
  min-width: 78px;
  padding: 0px 0.25em;
}
td.icon {
    width: 40px;
    max-width: 40px;
    text-align: center;
}

.icon {
  width: 14px;
  height: 14px;
  vertical-align: middle;
}

#databases {
  width: 50%;
}

#taskTable {
  min-width: 50%;
}

.spacer { flex: 1; }

/* Shell: desktop/tablet layout */
.app-shell {
  height: calc(95dvh - (var(--header-h) + var(--nav-h)));
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: var(--gap);
  padding: var(--gap);
}

.sidebar {
  overflow: auto;
  background: white;
}

.sidebar .treeItem,
.sidebar .treeLabel,
.sidebar li,
.sidebar a,
.sidebar span {
  white-space: nowrap;
}

.content {
  overflow-x: auto;
  overflow-y: auto;
  background: white;
}

/* Backdrop for drawer */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 30;
}
.drawer-handle {
  display: none;
}
.drawer-handle:hover {
  font-weight: bold;
}

  /* Forms */

  .search-view {
    padding: 8px 12px;
  }

  .search-card {
    max-width: 680px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
  }

  .search-title {
    margin: 0 0 14px 0;
    font-size: 1.1rem;
  }

  .search-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .search-field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
  }

  .search-field input[type="text"] {
    width: 100%;
    max-width: 420px;
    padding: 8px 10px;
    box-sizing: border-box;
    border: 1px solid #bbb;
    border-radius: 8px;
    font: inherit;
  }

  .search-help {
    margin-top: 6px;
    font-size: 0.9em;
    color: #666;
  }

  .search-fieldset {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px 12px 12px 12px;
    margin: 0;
  }

  .search-fieldset legend {
    padding: 0 6px;
    font-weight: 600;
  }

  .radio-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 8px 0;
  }

  .radio-option input[type="radio"] {
    margin-top: 2px;
  }

  .search-actions {
    display: flex;
    justify-content: flex-end;
  }

  .search-actions button {
    padding: 9px 16px;
    border: 1px solid #bbb;
    border-radius: 8px;
    background: #f5f5f5;
    font: inherit;
    cursor: pointer;
  }

  .search-actions button:hover {
    background: #ebebeb;
  }

.admin-view {
  padding: 8px 12px;
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.subnav a {
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  background: #f7f7f7;
}

.subnav a:hover {
  background: #ececec;
}

/* Admin forms and messages */

.admin-card {
  background: #fff;
  /* border: 1px solid #ddd;
  border-radius: 10px; */
  padding: 16px;
}

.admin-card table td:last-child {
  word-break: break-word;
}

.admin-title {
  margin: 0 0 14px 0;
  font-size: 1.1rem;
}

.admin-info {
  margin: 0 0 12px 0;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.admin-inline-form {
  max-width: 420px;
}

.admin-field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.admin-field input,
.admin-field select,
.admin-field textarea {
  width: 100%;
  padding: 8px 10px;
  box-sizing: border-box;
  border: 1px solid #bbb;
  border-radius: 8px;
  font: inherit;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-actions button {
  padding: 9px 16px;
  border: 1px solid #bbb;
  border-radius: 8px;
  background: #f5f5f5;
  font: inherit;
  cursor: pointer;
}

.admin-actions button:hover {
  background: #ebebeb;
}

.admin-message {
  margin: 0 0 14px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 600;
}

.admin-message-ok {
  background: #eaf7ea;
  color: #1f6b2a;
}

.admin-message-error {
  background: #fdeaea;
  color: #b00020;
}

.admin-log-output {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fafafa;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
}

.user-menu {
  position: relative;
}

.user-menu-button {
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}

.user-menu-button:hover {
  background: #f2f2f2;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 180px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  padding: 6px 0;
  z-index: 100;
}

.user-menu-name {
  padding: 8px 12px;
  font-weight: 600;
  border-bottom: 1px solid #eee;
}

.user-menu-panel a {
  display: block;
  padding: 8px 12px;
  text-decoration: none;
  color: inherit;
}

.user-menu-panel a:hover {
  background: #f5f5f5;
}

[x-cloak] {
  display: none !important;
}


/* Responsive adjustments */

@media (max-width: 1200px) {
  td {
    padding: 3px 0.5em;
  }
  #databases {
    width: 75%;
  }
}

/*********************************************/
/* MOBILE: sidebar becomes off-canvas drawer */
/*********************************************/
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr; /* content only */
    padding: 0;
  }

  .sidebar {
    position: fixed;
    top: calc(var(--header-h) + var(--nav-h)*3.5);
    left: 0;
    height: calc(100dvh - (var(--header-h) + var(--nav-h)*3.5));
    width: 85%; /*min(90vw, var(--sidebar-w)); */
    transform: translateX(-105%);
    transition: transform 180ms ease;
    z-index: 40;
    border-radius: 0 12px 12px 0;
  }

  .drawer-handle {
    display: block;
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    z-index: 45;

    background: #f2f2f2;
    border: 1px solid #ccc;
    border-left: none;

    padding: 10px 6px;
    border-radius: 0 12px 12px 0;

    cursor: pointer;
    font-size: 18px;

    box-shadow: 2px 0 6px rgba(0,0,0,0.15);
  } 

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-open .backdrop {
    display: block;
  }
  #databases {
    width: 90%;
  }

  /* MOBILE: tables become list-like cards. Forms excluded */

  table {
    border: none;
    width: 100%;
  }

  table thead {
    display: none;
  }

  table tr {
    display: block;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
  }

  table td:empty {
    display: none;
  }

  table td {
    display: flex;
    border: none;
    padding: 0 4px;
  }

  table td::before {
    content: attr(lbl);
    font-weight: bold;
    flex: 0 0 18%;
    max-width: 18%;
    padding-right: 8px;
  }

  .search-view {
    padding: 4px;
  }

  .search-card {
    padding: 12px;
    border-radius: 8px;
  }

  .search-actions {
    justify-content: stretch;
  }

  .search-actions button {
    width: 100%;
  }

  /* hide 'Download' in mobile view */
  #databases .download {
    display: none;
  } 
  
  
}

@media (max-width: 480px) {
  .login-page {
    padding: 16px 12px;
  }

  .login-card {
    padding: 18px;
    border-radius: 10px;
  }

  .login-title {
    font-size: 1.15rem;
  }
  td {
    align-items: start;
  }
  #contentArea {
    margin: 4px;
  }
  main {
    margin: 4px;
  }

  /* hide 'Attachments' in mobile view */
  #serviceHistory th:nth-of-type(8),  
  #serviceHistory td:nth-of-type(8) {
    display: none;
  }  

  .admin-view {
    padding: 4px;
  }

  .admin-card {
    padding: 12px;
    border-radius: 8px;
  }

  .admin-actions button {
    width: 100%;
  }

}